I have an array like below
Array
(
[0] => stdClass Object
(
[id] => 1
[cat_id] => 1
[item_name]=>test1
[cat_name] => Normal
)
[1] => stdClass Object
(
[id] => 2
[cat_id] => 2
[item_name]=>test2
[cat_name] => Featured
)
[2] => stdClass Object
(
[id] => 3
[cat_id] => 2
[item_name]=>test3
[cat_name] => Featured
)
)
And I want the result to look like this
Normal
test1
Featured
test2 | test3
I have try this so far:
<?php
foreach($rows as $row){
echo '<h2>'.$row->cat_name.'</h2>';
echo '<p>'.$row->item_name.'</p>';
}
?>
But it shows the heading with each of the item.Can someone help me to sort this out.
Thanks