How to display array structure and values in PHP

Topic: PHP / MySQL« Prev|Next »

Answer: Use the PHP print_r() or var_dump() Statement

You can use either the PHP print_r() or var_dump() statement to see or check the structure and values of an array in human-readable format on the screen. The var_dump() statement however gives more information than print_r().

  • <?php
  • $cities = array("London", "Paris", "New York");
  •  
  • // Print the cities array
  • Print_r($cities);
  • echo "<hr>";
  • var_dump($cities);
  • ?>

Related FAQ

Here are some more FAQ related to this topic:

 
Close

Your Feedback:

 

We would love to hear from you! Please say something.