Question

I'm trying to filter the array output of GET search/tweets (remove tweets with empty 'geo' key and keep the tweets with 'geo' key) by using this piece of code.

$data = (array) $cb->search_tweets($params); //copy of raw print_r array here: http://pastebin.com/b2BvwUuJ

$filtered = array_filter($data, function($v) { 

    return $v['geo'] != 'false'; 

});

print_r($filtered);

It results in the following error code.

Cannot use object of type stdClass as array in ...

What am I doing wrong?

Was it helpful?

Solution

The results you have are not arrays, are objects. Change the comparison to this:

return $v->geo != 'false'; 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top