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

Displaying an array as a comma-separated list - PHP Tutorial

From the course: PHP for Web Designers

Start my 1-month free trial

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…

Contents