php - foreach loop with decoded json data -
i'm trying data json response displayed using foreach
loop. if try error:
invalid argument supplied foreach()
the data put in foreach
loop isn't null or empty, checked that.
my code:
$json = file_get_contents($goodurl); $the_data = json_decode($json, true); $count = 0; foreach($the_data->response $video) { //case show results text //echo $video->title; $html.= "<p><div class='p2go_title'><a href='". $video->playbackurl ."' target='_blank'>" . $video->title . "</a></div>"; $html.= "<div class='p2go_contributors'>by: ". $video->contributors ."</div>"; $html.= "<div class='p2go_views'>views: ". $video->views ."</div></p>"; $count++; } return $html;
$the_data
array. try -
foreach($the_data['response'] $video)
json_decode($json, true);
return array. second parameter used only.
update
the inner elements needed accesed array -
$html.= "<p><div class='p2go_title'><a href='". $video['playbackurl'] ."' target='_blank'>" . $video['title'] . "</a></div>"; $html.= "<div class='p2go_contributors'>by: ". $video['contributors'] ."</div>"; $html.= "<div class='p2go_views'>views: ". $video['views'] ."</div></p>";
Comments
Post a Comment