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

  • SEARCH
  • Home
  • 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 7824533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:37:53+00:00 2026-06-02T08:37:53+00:00

How can I loop through this array and print one result in each line.

  • 0

How can I loop through this array and print one result in each line. This is returned by google search api.

This works for me

print_r($rez->responseData);

But this doesn’t

print_r($rez->responseData->results); nor this print_r($rez->responseData['results']);

Below is the array

        stdClass Object
(
    [results] => Array
        (
            [0] => stdClass Object
                (
                    [GsearchResultClass] => GwebSearch
                    [unescapedUrl] => http://www.1860-1960.com/shoes.html
                    [url] => http://www.1860-1960.com/shoes.html
                    [visibleUrl] => www.1860-1960.com
                    [cacheUrl] => http://www.google.com/search?q=cache:4bB2OicXg5EJ:www.1860-1960.com
                    [title] => Beautiful <b>Antique Shoes</b> and Boots, Vintage Fashions
                    [titleNoFormatting] => Beautiful Antique Shoes and Boots, Vintage Fashions
                    [content] => <b>Vintage</b> Clothing. <b>Shoes</b> &amp; boots Hats &amp; bonnets. Parasols, purses, fans &amp; more.   Textiles &amp; trims. New Items. ebay auctions. Find out how to order About us Click <b>...</b>
                )

            [1] => stdClass Object
                (
                    [GsearchResultClass] => GwebSearch
                    [unescapedUrl] => http://www.ebay.com/sch/Pre1920-Edwardian-Older-/74977/i.html?_nkw=antique+shoes
                    [url] => http://www.ebay.com/sch/Pre1920-Edwardian-Older-/74977/i.html%3F_nkw%3Dantique%2Bshoes
                    [visibleUrl] => www.ebay.com
                    [cacheUrl] => http://www.google.com/search?q=cache:gKFzby7zoS0J:www.ebay.com
                    [title] => <b>antique shoes</b> | eBay
                    [titleNoFormatting] => antique shoes | eBay
                    [content] => eBay: <b>antique shoes</b>. <b>...</b> Quick Look. Antique 1905 Silk Satin Bridal Wedding   Shoes Pumps Louis XV Heels Beautiful. Buy It Now $31.90 <b>...</b>
                )

            [2] => stdClass Object
                (
                    [GsearchResultClass] => GwebSearch
                    [unescapedUrl] => http://www.amazon.com/Winsome-Wood-Shoe-Antique-Walnut/dp/B000NPQKHO
                    [url] => http://www.amazon.com/Winsome-Wood-Shoe-Antique-Walnut/dp/B000NPQKHO
                    [visibleUrl] => www.amazon.com
                    [cacheUrl] => http://www.google.com/search?q=cache:SBPbbjdSIpMJ:www.amazon.com
                    [title] => Amazon.com: Winsome Wood <b>Shoe</b> Rack, <b>Antique</b> Walnut: Home <b>...</b>
                    [titleNoFormatting] => Amazon.com: Winsome Wood Shoe Rack, Antique Walnut: Home ...
                    [content] => <b>Shoe</b> Rack. With Removable Sink tray, this unique product is nice to have it   especially in wet weather.Warm Walnut finish <b>...</b>
                )

            [3] => stdClass Object
                (
                    [GsearchResultClass] => GwebSearch
                    [unescapedUrl] => http://trouvais.com/category/antique-shoes/
                    [url] => http://trouvais.com/category/antique-shoes/
                    [visibleUrl] => trouvais.com
                    [cacheUrl] => http://www.google.com/search?q=cache:qPcTFS0bBR4J:trouvais.com
                    [title] => <b>Antique shoes</b> « Trouvais
                    [titleNoFormatting] => Antique shoes « Trouvais
                    [content] => 19th century silk <b>shoes</b>, and then stumbled upon. this tattered silk pair inscribed   with a wedding date c1773. <b>antique</b> textiles. I&#39;m happy with just a few tangible <b>...</b>
                )

        )

    [cursor] => stdClass Object
        (
            [resultCount] => 11,400,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] => 11400000
            [currentPageIndex] => 0
            [moreResultsUrl] => http://www.google.com/search?oe=utf8&ie=utf8&source=uds&start=0&hl=en&q=antique+shoes
            [searchResultTime] => 0.14
        )

)

This is the code that generates this.

<?php 

/**
 * google_search_api()
 * Query Google AJAX Search API
 *
 * @param array $args URL arguments. For most endpoints only "q" (query) is required.
 * @param string $referer Referer to use in the HTTP header (must be valid).
 * @param string $endpoint API endpoint. Defaults to 'web' (web search).
 * @return object or NULL on failure
 */
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);
}


print_r($rez->responseData);
  • 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-06-02T08:37:55+00:00Added an answer on June 2, 2026 at 8:37 am

    Something like:

    $obj = new obj(); // your object
    
    function printLies($obj)
    {
        foreach ($obj as $elem)
        {
            if (is_array($elem) || is_object($elem))
            {
                printLies($obj);
            }
            else
            {
                echo $elem . '<br />';
            }
        }
    }
    

    Or I didn’t understand the question? Maybe you meant this?

    $obj = new obj(); // your object
    
    foreach ($obj->result as $result)
    {
        print_r($result);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I loop through this json data without referring to the data items
I know I can loop through a list of strings like this: list<string>::iterator Iterator;
I want to know that How can I walk through this loop ? this
How can I loop through the array below and an element per array, with
How can I modify my existing JQuery code to loop through a JSON array
How can I loop through all members in a JavaScript object, including values that
How can I loop through directories with specified nesting index using C#? Little example:
Using a for loop, how can I loop through all except the last item
/// \todo Loop must be rewritten ... /// \todo Delete this loop Can Doxygen
I've got an array var cells = new Cell[w, h] , can I loop

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.