Home > Articles > Programming > PHP

  • Print
  • + Share This
This chapter is from the book

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.

  • + Share This
  • 🔖 Save To Your Account