How can I echo or print an array in PHP?

To see the contents of array you can use:

  1. print_r($array); or if you want nicely formatted array then:

     echo '<pre>'; print_r($array); echo '</pre>';
    
  2. Use var_dump($array) to get more information of the content in the array like the datatype and length.

  3. You can loop the array using php’s foreach(); and get the desired output. More info on foreach is in PHP’s documentation website: foreach

Leave a Comment