PHP JSON foreach Array Issue -
i'm trying use php display json data api. need use foreach return results nested within them array. array "highlights" has "description" , "content" , both. need foreach within foreach or along lines try returns "array".
here's json...
here's php...
$json_returned = file_get_contents("json_url"); $decoded_results = json_decode($json_returned, true); echo "number found:".$decoded_results['numfound']."</br> "; echo "start:".$decoded_results['start']."</br>"; echo "max score:".$decoded_results['maxscore']."</br>"; foreach($decoded_results['docs'] $results){ echo "parent link t:".$results['parent_link_t']."</br>"; echo "description:".$results['highlights']['description']."</br>"; }
obviously working version i'm using has lot more fields programmed in cut them out keep code short , simple , show how have else besides "hightlights" field in 1 foreach. json returns require keep in foreach, how display array inside of it?
thanks , taking time read if can contribute.
the 'description' array 1 element can use this.
echo 'description:' . $results['highlights']['description'][0];
if has 'description' , 'content'. use isset check 1 is, or if there both , print accordingly.
// description if(isset($results['highlights']['description'])) { echo 'description:' . $results['highlights']['description'][0]; } // content if(isset($results['highlights']['content'])) { echo 'content:' . $results['highlights']['content'][0]; }
hope helps.
Comments
Post a Comment