SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    echo the results of this PHP array

    Can someone teach me how to echo the results of this PHP array? Sorry but Iím just a beginner so I donít know how to echo the results by print_r. Thanks in advance.

    Here is the test result.
    Code:
    Array
        (
        [html_attributions] => Array
            (
            )
    
        [result] => Array
            (
                [address_components] => Array
                    (
                        [0] => Array
                            (
                                [long_name] => 101
                                [short_name] => 101
                                [types] => Array
                                    (
                                        [0] => street_number
                                    )
    
                            )
    
                        [1] => Array
                            (
                                [long_name] => South Capitol Boulevard
                                [short_name] => South Capitol Boulevard
                                [types] => Array
                                    (
                                        [0] => route
                                    )
    
                            )
    
                        [2] => Array
                            (
                                [long_name] => Boise
                                [short_name] => Boise
                                [types] => Array
                                    (
                                        [0] => locality
                                        [1] => political
                                    )
    
                            )
    
                        [3] => Array
                            (
                                [long_name] => ID
                                [short_name] => ID
                                [types] => Array
                                    (
                                        [0] => administrative_area_level_1
                                        [1] => political
                                    )
    
                            )
    
                        [4] => Array
                            (
                                [long_name] => US
                                [short_name] => US
                                [types] => Array
                                    (
                                        [0] => country
                                        [1] => political
                                    )
    
                            )
    
                        [5] => Array
                            (
                                [long_name] => 83702
                                [short_name] => 83702
                                [types] => Array
                                    (
                                        [0] => postal_code
                                    )
    
                            )
    
                    )
    
                [formatted_address] => 101 South Capitol Boulevard #102, Boise, ID, United States
                [formatted_phone_number] => (208) 383-7990
                [geometry] => Array
                    (
                        [location] => Array
                            (
                                [lat] => 43.614959
                                [lng] => -116.20324
                            )
    
                    )
    
                [icon] => http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png
                [id] => 91bf0748c063de6e9bf44c727ad51f4ef85d33ae
                [international_phone_number] => +1 208-383-7990
                [name] => U.S. Bank
                [photos] => Array
                    (
                        [0] => Array
                            (
                                [height] => 960
                                [html_attributions] => Array
                                    (
                                    )
    
                                [photo_reference] => CpQBiQAAAJ5QC7jSXHz6OUGp1FPaA55yn5BE9fZ6fxOzT1s4FFIIsvGvAecrFYK2eZZyrqI9nB8pRAdlwoJiSZkdxk-JtJawfmwCCr_fChdG-0T-iDyRnTlxRf5IAbsWb4r_AxX-B7uOlJCdoqzlqhdGmrA66ZDOKQLl-b_wabnfWFOEQFVCoUdJm4DuYWqva1kxH1ZWrRIQkc0ouj-W6VPrPWHm6V9jahoU-fIZnYc1jGMnhHKjgPdyDFR5aKM
                                [width] => 960
                            )
    
                    )
    
                [reference] => CnRmAAAAMALLK7dmAZaKc0ESh4shESTdKRgs4a003f2Cm_ZQeCicE0kcbS54t5lZeQPgLQKmzH6PlzQRE_0TeHOw-1y6M_5esCUsMFmWbO0jDRSZ4ZTnXClSnof70T88tyIT7GXD_zXaQ13jSTgz_IfvSE6J4xIQxVgnzxjMyK2H5jrA9LyrTRoUueDADLmJEnqYUDYcS-Td_0VfVwQ
                [reviews] => Array
                    (
                        [0] => Array
                            (
                                [aspects] => Array
                                    (
                                        [0] => Array
                                            (
                                                [rating] => 0
                                                [type] => overall
                                            )
    
                                    )
    
                                [author_name] => A Google User
                                [text] => Not helpful. Pain in the butt to work with. Tried to close my account multiple times and they'd just talk me in circles until I ran out of time and had to head to work or the store etc.
                                [time] => 1305826914
                            )
    
                    )
    
                [types] => Array
                    (
                        [0] => atm
                        [1] => bank
                        [2] => finance
                        [3] => establishment
                    )
    
                [url] => https://plus.google.com/109932745180214578046/about?hl=en
                [utc_offset] => -420
                [vicinity] => 101 South Capitol Boulevard #102, Boise
                [website] => http://usbank.com/
                [address_fixed] => Array
                    (
                        [street_number] => 101
                        [address_street_name] => South Capitol Boulevard
                        [address_city] => Boise
                        [address_state] => ID
                        [address_postal_code] => 83702
                    )
    
            )
    
        [status] => OK
        [errors] => Array
            (
            )
    
    )
    Here is my PHP script.

    PHP Code:
    <?
        
    require_once('googlePlaces.php');
        
    //Searching a new place
        
    $gplaces = New GooglePlaces;
        
    $gplaces->SetLocation("43.612631,-116.211076");
        
    $gplaces->SetRadius(50000);
        
    $gplaces->SetTypes("bank");
        
    $results $gplaces->Search();


        if(
    $results[status] = "OK")
        {
            
    $num_of_results count($results[results]);
            
            
    $result_counter 1;
            foreach(
    $results[results] as $key=>$current_result)
                {
                    if(
    $result_counter >= 5)
                        {
                            continue;    
                        }
                    
                    
    $gplaces->SetReference($current_result[reference]);
                    
    $details_result $gplaces->Details();
                    echo 
    "<pre>";
                    
    print_r($details_result);
                    echo 
    "</pre>";
                    echo 
    "<hr>";
                    
                    
    $result_counter++;
                }
        }
    ?>

  2. #2
    SitePoint Enthusiast
    Join Date
    Dec 2011
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, for a start, what do you want to echo? What do you want displayed?
    That result contains a ton of information in an array, we can cut it down some...

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    print_r will iterate through an array, outputting the contents.

    var_dump() does similar, and var_export() is also helpful.

    If you were to post here that array you posted initially, but instead showed us the result of:
    PHP Code:
    $array = (this is your array of results)

    echo 
    var_export($array1); 
    and then tell us what you want to extract from that array, someone can then show you how best to iterate (loop) through your array and output the results you wanted.

    As it is we have to guess what you want and we have to type out that array ourselves in order to reproduce it. Hence the var_export request


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •