Converting Arrays to Strings


 $address = implode('<br />', $data); 


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.

Turning an Array into a String (implode.php)
 <?php   $data = array(     'Sams Publishing',     '800 East 96th Street',     'Indianapolis',     'Indiana',     '46240'   );   $address = implode('<br />', $data);   echo $address; ?> 




PHP Phrasebook
PHP Phrasebook
ISBN: 0672328178
EAN: 2147483647
Year: 2005
Pages: 193

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net