I have this problem regarding an if/elseif condition in a foreach look. I have searched over and over and really out of ideas. So I have this array:
Array (
[0] => stdClass Object
(
[title] => main
[value] => value1
)
[1] => stdClass Object
(
[title] => other
[value] => value2
)
[2] => stdClass Object
(
[title] => second
[value] => value3
)
[3] => stdClass Object
(
[title] => other
[value] => value4
)
[4] => stdClass Object
(
[title] => other
[value] => value5
)
)
As you can see obj0 has title=>main and obj2 has title=>second, the rest of "titles" are set to other.
I have this foreach:
foreach ($objects as $object):
if($object->title == 'second') {
//this value is rarely added, so it must have a "priority" and be showed
echo '<span></span>';
} elseif($object->title == 'main') {
//i mostly want to show this, but not if $object->title has the value 'second'.
echo '<div></div>';
}
endforeach;
This loop returnes both "span" and "div" which i don't want. I can't manage to show only title=>"second" (if it's there), and title=>"main" only if "second" doesn't exist. So either display spans, either div's.
Hope i explained good, if not i apologize! Thank you very much and i really appreciate your help!
Marius