이것이 효과가있는 것 같습니다
$urls = array_map(function($result) {
return $result->url;
}, $rez->responseData->results);
문제
비 작업 코드 :
통지 : 비 객체의 재산을 얻으려고합니다
$i = 1;
var_dump($rez->responseData->results[$i]->url);
치명적인 오류 : stdclass 유형의 객체를 배열로 사용할 수 없습니다.
$rez = (array) $rez;
var_dump($rez['responseData']['results']['1']['url']);
작업 코드 결과 :
URL 만 확장하고 URL 목록을 배열로 바꾸는 방법은 무엇입니까?
stdClass Object
(
[responseData] => stdClass Object
(
[results] => Array
(
[0] => stdClass Object
(
[GsearchResultClass] => GwebSearch
[unescapedUrl] => http://www.rottentomatoes.com/top/
[url] => http://www.rottentomatoes.com/top/
[visibleUrl] => www.rottentomatoes.com
...........................................................................
작업 코드 :
function google_search_api($args, $referer = 'http://localhost/test/', $endpoint = 'web'){
$url = "http://ajax.googleapis.com/ajax/services/search/".$endpoint;
if ( !array_key_exists('v', $args) )
$args['v'] = '1.0';
$url .= '?'.http_build_query($args, '', '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// note that the referer *must* be set
curl_setopt($ch, CURLOPT_REFERER, $referer);
$body = curl_exec($ch);
curl_close($ch);
//decode and return the response
return json_decode($body);
}
$rez = google_search_api(array(
'q' => 'movie list', 'start' => '5',
));
echo '<pre>';
print_r($rez);
echo '</pre>';
?>
나는 위의 여러 변형을 시도했지만 그것을 알아 내지 않습니다. 아마도 간단한 것이 있으므로 어떤 의견도 감사 할 것입니다.
해결책
이것이 효과가있는 것 같습니다
$urls = array_map(function($result) {
return $result->url;
}, $rez->responseData->results);