How do I echo a certain result from a PHP foreach loop?

scripts

#1

How do I echo a certain result from a PHP foreach loop?


#2

Perhaps you can show us the code you have and show us what certain result you want to echo, @Sajjao?


#3

You can use echo inside the foreach() statement and output the result.

Simple e.g,

$array = [‘one’, ‘two’, ‘three’, ‘four’, ‘five’, ‘six’];

// to display the result one by one

foreach($array as $item) {

echo $item.’<br>’;

}

Note: Here am using static array. You can get your dynamic results in an array and display using like above example.