문제

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?

도움이 되었습니까?

해결책

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

return $v->geo != 'false'; 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top