In this tutorial we will learn How To Echo array values using foreach loop in PHP. Echo statement doesn't print or display array values directly but we can use foreach loop with echo statement to echo all values of array.
Table of Contents
PHP echo Statement
PHP echo statement is used to output or print data on screen.
<?php
echo "HowToCodeSchool.com"; // Output HowToCodeSchool.com
?>
PHP foreach Loop
foreach loop is a loop made for array to loop through it's values. The number of times loop runs is equal to the number of values or elements present in array.
<?php
foreach ($array as $value) {
// code here
}
?>
Let's see how to echo array values using foreach loop and echo statement.
<?php
$array = array("HTML", "CSS", "JavaScript", "PHP");
foreach ($array as $value)
{
echo "$value" . "<br>";
}
?>