From the course: PHP for Web Designers
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Displaying an array as a comma-separated list - PHP Tutorial
From the course: PHP for Web Designers
Displaying an array as a comma-separated list
If you attempt to use echo or print to display the whole contents of an array it wont work in PHP. In this page an array has been created above the Doctype on lines two and three and on line 15 echo is being used in an attempt to display the contents of the array. Let's see what that look like, in a browser, and we'll just zoom in to read that more clearly. And it says array to string conversion, gives the location, and then simply displays the word Array. Unlike Javascript, PHP doesn't automatically convert the array to a string. You need to convert it yourself using the delightfully named implode function. It's called that because it does the opposite of another function called explode that breaks a string into an array. So let's see how implode works let's go back to the editing program. We still need echo because that will display the output of the implode function, but we need to pass flowers, the array, as the argument to the implode function. So, implode, and then the argument…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Storing multiple values in a variable as an array4m 28s
-
(Locked)
Inspecting an array's elements4m 13s
-
(Locked)
Challenge: Inserting the appropriate alt text1m 27s
-
(Locked)
Solution: Inserting the appropriate alt text5m 26s
-
(Locked)
Displaying an array as a comma-separated list3m 13s
-
(Locked)
Looping through an array's values7m 17s
-
(Locked)
Labeling array elements7m 21s
-
(Locked)
Looping through an array's labels and values5m 29s
-
Finding if a value exists in an array3m 51s
-
(Locked)
Challenge: Displaying a seasonal feature3m 6s
-
(Locked)
Solution: Displaying a seasonal feature8m 30s
-
(Locked)
-
-
-
-