Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7011435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:07:37+00:00 2026-05-27T22:07:37+00:00

I have this piece of code: return json_decode($body); This return is from a function

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:07:37+00:00Added an answer on May 27, 2026 at 10:07 pm

    Assuming that the data above is held in a variable called $returnedData:

    This version works if you use return json_decode($body);:

    $results = array();
    foreach ($returnedData->responseData->results as $result) {
      $results[] = array(
        'url' => $result->url,
        'title' => $result->title,
        'content'=>$result->content
      );
    }
    
    print_r($results);
    

    …and this version works if you use return json_decode($body,true);:

    $results = array();
    foreach ($returnedData['responseData']['results'] as $result) {
      $results[] = array(
        'url' => $result['url'],
        'title' => $result['title'],
        'content'=>$result['content']
      );
    }
    
    print_r($results);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this piece of code: begin complete_results = Timeout.timeout(4) do results = platform.search(artist,
So I have this piece of code that would return the current EST Date
I have this piece of code that runs a function to transform a color
I have this piece of code: $(#faq).click(function () { var url = $.get(faq, {
I have this piece of code: var myObj = function () { this.complex =
I have this piece of code that does not work: public CartaoCidadao() { InitializeComponent();
I have this piece of code that works fine in subsonic 2.2, I migrated
I have this piece of code // TR Fading when deleted $('.delete').live('click', function() {
I have this piece of code for email verification : function VerifRegisterEmail(&$email) { if(empty($email))
I have this piece of code: $(document).on(click, #breadNavMain, function() { for(var i = 0;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.