I have a slider for news items and doing a loop to get post info for each. Works fine but I am stuck with one paramater that is returned by json and I loop trough it again . the $xtras parameter returns some additional values one of them is additional intro text. I need to check if this value isset otherwise I need to return default intro text.
problem I have is that if $xtra_values->id 44 does not exists I get the intro text from previous post instead that post $post['intro']
$xtras returns stdClass Object like this
stdClass Object
(
[id] => 1
[value] => 38
)
stdClass Object
(
[id] => 28
[value] => 1
)
stdClass Object
(
[id] => 44
[value] => This is extra intro text
)
and this is my loop
foreach ($post_array as $key=> $posts){
$xtras = json_decode($posts['xtra']);
foreach($xtras as $key=> $xtra_values){
if($xtra_values->id == 44){
$intro_text = $xtra_values->value;
}else{
$intro_text = $post['intro'];
}
}
echo $post['title'];.'<br />';
echo $intro_text;
}
Any help is appreciated. Thank you!