WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES

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:

<?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:

Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties