␡
- Accessing All Elements of Numeric Arrays
- Accessing All Elements of Associative Arrays
- Accessing All Array Elements in Nested Arrays
- Turning an Array into Variables
- Converting Strings to Arrays
- Converting Arrays to Strings
- Sorting Arrays Alphabetically
- Sorting Associative Arrays Alphabetically
- Sorting Nested Arrays
- Sorting Nested Associative Arrays
- Sorting IP Addresses (as a Human Would)
- Sorting Anything
- Sorting with Foreign Languages
- Applying an Effect to All Array Elements
- Filtering Arrays
- Getting Random Elements Out of Arrays
- Making Objects Behave Like Arrays
This chapter is from the book
Converting Arrays to Strings
$address = implode('<br />', $data);
<?php $data = array( 'Pearson Education', '800 East 96th Street', 'Indianapolis', 'Indiana', '46240' ); $address = implode('<br />', $data); echo $address; ?>
Turning an Array into a String (implode.php)
The way back (that is, making a string representation out of the elements in an array) can be done using implode(). Again, two parameters are required: the separation elements, then the array. The order is quite unusual, yet important.
So, PHP joins the elements of the array, using the <br /> HTML element. Therefore, in the browser, each array’s elements stay at its own line.