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

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

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

2 Likes

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.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.