I have a php script that uses curl to get the contents of a json feed. Everything works fine until i try to return the “q” values in the json feed. The code below only returns “null”. How can I fix this? I suspect it has to do with the line $search_term = $term[$number]->q; but I am not 100% sure.
$lmgtfy_json_feed = get_data('http://live.com/');
$lmgtfy_search_term = json_decode($lmgtfy_json_feed);
$number = rand(0, count($lmgtfy_search_term)-1);
$search_term = $lmgtfy_search_term[number]->q;
echo json_encode($search_term);
You are using your complete array
$numberas key for$term.If you want to pick a random element from the array
$term, use PHP’srandfunction instead of creating and shuffling an array: