How to echo or print an array in PHP?

EnexoOnoma picture EnexoOnoma · Mar 22, 2012 · Viewed 947.7k times · Source

I have this array

Array
(
  [data] => Array
    (
      [0] => Array
        (
          [page_id] => 204725966262837
          [type] => WEBSITE
        )

      [1] => Array
        (
          [page_id] => 163703342377960
          [type] => COMMUNITY
        )
      )
)

My question is how can I just echo the content without this structure? I tried

foreach ($results as $result) {
    echo $result->type; 
    echo "<br>";
} 

Answer

Ibrahim Azhar Armar picture Ibrahim Azhar Armar · Mar 22, 2012

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 datatype and length.

3) you can loop the array using php's foreach(); and get the desired output. more info on foreach in php's documentation website:
http://in3.php.net/manual/en/control-structures.foreach.php