php - Iterating through an associative array -
i trying twitter followers specific user api call
https://api.twitter.com/1/users/lookup.json?screen_name=twitterapi,twitter&include_entities=true and there sample output there:
https://dev.twitter.com/docs/api/1/get/users/lookup i trying screen name of user doing following:
$json2=file_get_contents('http://api.twitter.com/1/users/lookup.json?user_id='.$post.'') ; $accounts2 = json_decode($json2); while( $element = each( $accounts2 ) ) { echo $element[ 'screen_name' ]; echo '<br />'; } where $post ids (around 100) concatenated together.
the above fail with:
notice: trying property of non-object any please?
replace line:
$accounts2 = json_decode($json2); with this:
$accounts2 = json_decode($json2, true); it converts associative array. because user_id unique, don't have loop through results, can this:
echo $accounts2[0]['screen_name'] . '<br />';
Comments
Post a Comment