Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this 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>";
}
?>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP  and MySQL Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to display array structure and values in PHP... >>
<< How to count all elements or values in an array in...