How to print or echo all the values of an array in PHP

Topic: PHP / MySQL« Prev|Next »

Answer: Use the PHP foreach loop

There are so many ways of printing an array values, however the simplest method is using the foreach loop. In the following example we iterate over the $colors array and print all its elements using the echo or print statement.

  • <?php
  • $colors = array("Red", "Green", "Blue", "Yellow", "Orange");
  • // Loop through colors array
  • foreach($colors as $value){
  •     echo $value . "<br>";
  • }
  • ?>

Related FAQ

Here are some more FAQ related to this topic:


Your Feedback:


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