Приглашаем посетить
Романтизм (19v-euro-lit.niv.ru)

Converting Arrays to Strings

Previous
Table of Contents
Next

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;
?>


Previous
Table of Contents
Next