How to print or echo all the values of an array in PHP
Topic: PHP / MySQLPrev|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've iterated over the $colors
array and print all its elements using the echo
or print
statement. Let's try it out and see how it works:
Example
Try this code »<?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: