I have this piece of code:
return json_decode($body);
This return is from a function that gets from google some search results. If I print that it wil be for example:
stdClass Object
(
[responseData] => stdClass Object
(
[results] => Array
(
[0] => stdClass Object
(
[GsearchResultClass] => GwebSearch
[unescapedUrl] => http://www.bmw.com/
[url] => http://www.bmw.com/
[visibleUrl] => www.bmw.com
[cacheUrl] => http://www.google.com/search?q=cache:ys7v8m0j3LMJ:www.bmw.com
[title] => BMW automobiles - website of the BMW AG
[titleNoFormatting] => BMW automobiles - website of the BMW AG
[content] => The official BMW AG website: BMW automobiles, services, technologies and all about BMWs sheer driving pleasure.
)
[1] => stdClass Object
(
[GsearchResultClass] => GwebSearch
[unescapedUrl] => http://www.bmwusa.com/
[url] => http://www.bmwusa.com/
[visibleUrl] => www.bmwusa.com
[cacheUrl] => http://www.google.com/search?q=cache:W59Q9fpm9PkJ:www.bmwusa.com
[title] => BMW of North America, LLC
[titleNoFormatting] => BMW of North America, LLC
[content] => BMW ConnectedDrive. Reads Facebook posts and emails. Forecasts the weather. Maps routes. Parks your car. And much more. The All-New 6 Gran Coupe ...
)
[2] => stdClass Object
(
[GsearchResultClass] => GwebSearch
[unescapedUrl] => http://autos.yahoo.com/bmw/
[url] => http://autos.yahoo.com/bmw/
[visibleUrl] => autos.yahoo.com
[cacheUrl] => http://www.google.com/search?q=cache:yjHBrdiQI5UJ:autos.yahoo.com
[title] => New 2011, 2012 BMW Car Models - Yahoo! Autos
[titleNoFormatting] => New 2011, 2012 BMW Car Models - Yahoo! Autos
[content] => Yahoo! Autos - BMW Cars. Research all BMW 2012, 2011 car models. Compare new BMW vehicles; buy used BMWs for sale.
)
[3] => stdClass Object
(
[GsearchResultClass] => GwebSearch
[unescapedUrl] => http://www.motortrend.com/new_cars/01/bmw/
[url] => http://www.motortrend.com/new_cars/01/bmw/
[visibleUrl] => www.motortrend.com
[cacheUrl] => http://www.google.com/search?q=cache:8ur1ZNau24AJ:www.motortrend.com
[title] => New BMW Cars - Find 2012 2013 BMW Car Prices & Reviews ...
[titleNoFormatting] => New BMW Cars - Find 2012 2013 BMW Car Prices & Reviews ...
[content] => Matches 1 - 14 of 14 ... Find new BMW cars and 2012 2013 BMW cars at Motor Trend. Research a new BMW car, find BMW prices, read reviews, or buy a new ...
)
)
[cursor] => stdClass Object
(
[resultCount] => 16,700,000
[pages] => Array
(
[0] => stdClass Object
(
[start] => 0
[label] => 1
)
[1] => stdClass Object
(
[start] => 4
[label] => 2
)
[2] => stdClass Object
(
[start] => 8
[label] => 3
)
[3] => stdClass Object
(
[start] => 12
[label] => 4
)
[4] => stdClass Object
(
[start] => 16
[label] => 5
)
[5] => stdClass Object
(
[start] => 20
[label] => 6
)
[6] => stdClass Object
(
[start] => 24
[label] => 7
)
[7] => stdClass Object
(
[start] => 28
[label] => 8
)
)
[estimatedResultCount] => 16700000
[currentPageIndex] => 0
[moreResultsUrl] => http://www.google.com/search?oe=utf8&ie=utf8&source=uds&start=0&hl=en&q=bmw+cars
[searchResultTime] => 0.15
)
)
[responseDetails] =>
[responseStatus] => 200
)
Now, I tried to get with the function get_object_vars() but the same output will come. I want to put into an array the values but only the [ur] => ; [title] => and [content]=> ; how can i achieve that?
Assuming that the data above is held in a variable called
$returnedData:This version works if you use
return json_decode($body);:…and this version works if you use
return json_decode($body,true);: