Friends, how do you echo the data of php array using foreach loop. Today I will tell you through this tutorial.
php echo array values foreach, php foreach echo prints “Array” as value, PHP echo array by value in loop or foreach
Suppose $my_array variable as an example has array data.
<?php $my_array => Array ( [0] => Array ( ['id'] => 1 ['name'] => "Shri Radhe Radhe" ['age'] => 25 ) [1] => Array ( ['id'] => 2 ['name'] => "ShrI Site Site" ['age'] => 35 ) ) ?>
I will tell you through 2 method how you can make array data echoed by foreach loop. So let’s go.
This is First Method
<?php foreach($my_array as $item): echo '<span>'.$item['id'].'</span>'; echo '<span>'.$item['name'].'</span>'; echo '<span>'.$item['age'].';</span>'; endforeach; ?>
This is Second Method
<?php foreach($my_array as $item) { echo '<span>'.$item['id'].'</span>'; echo '<span>'.$item['name'].'</span>'; echo '<span>'.$item['age'].';</span>'; } ?>