Apply for Zend Framework Certification Training

Corephp




1)if the result is like this From api then to accesss element  retrieved in json_decode format

stdClass Object
(
    [results] => Array
        (
            [0] => stdClass Object
                (
                    [address_components] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [long_name] => 2
                                    [short_name] => 2
                                    [types] => Array
                                        (
                                            [0] => premise
                                        )

                                )

                            [1] => stdClass Object
                                (
                                    [long_name] => Pocket G-27
                                    [short_name] => Pocket G-27
                                    [types] => Array
                                        (
                                            [0] => political
                                            [1] => sublocality
                                            [2] => sublocality_level_3
                                        )

                                )

                           

                            [2] => stdClass Object
                                (
                                    [long_name] => India
                                    [short_name] => IN
                                    [types] => Array
                                        (
                                            [0] => country
                                            [1] => political
                                        )

                                )

                            )

                    [formatted_address] => 2, Pocket G-27, Sector 3G, Rohini, Delhi, 110085, India
                    [geometry] => stdClass Object
                        (
                            [location] => stdClass Object
                                (
                                    [lat] => 28.7041927
                                    [lng] => 77.1026283
                                )

                            [location_type] => ROOFTOP
                            [viewport] => stdClass Object
                                (
                                    [northeast] => stdClass Object
                                        (
                                            [lat] => 28.705541680291
                                            [lng] => 77.103977280292
                                        )

                                    [southwest] => stdClass Object
                                        (
                                            [lat] => 28.702843719709
                                            [lng] => 77.101279319708
                                        )

                                )

                        )

                    [place_id] => ChIJqXuS_f8DDTkR5wfrYpAgr5E
                    [types] => Array
                        (
                            [0] => street_address
                        )

                )

            [1] => stdClass Object
                (
                    [address_components] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [long_name] => nalamda apartments
                                    [short_name] => nalamda apartments
                                    [types] => Array
                                        (
                                            [0] => establishment
                                            [1] => point_of_interest
                                        )

                                )

                           

                            

                            [8] => stdClass Object
                                (
                                    [long_name] => 110085
                                    [short_name] => 110085
                                    [types] => Array
                                        (
                                            [0] => postal_code
                                        )

                                )

                        )

                    [formatted_address] => nalamda apartments, 2, Pocket G-27, Sector 3G, Rohini, Delhi, 110085, India
                    [geometry] => stdClass Object
                        (
                            [location] => stdClass Object
                                (
                                    [lat] => 28.7040592
                                    [lng] => 77.1024902
                                )

                            [location_type] => GEOMETRIC_CENTER
                            [viewport] => stdClass Object
                                (
                                    [northeast] => stdClass Object
                                        (
                                            [lat] => 28.705408180291
                                            [lng] => 77.103839180292
                                        )

                                    [southwest] => stdClass Object
                                        (
                                            [lat] => 28.702710219709
                                            [lng] => 77.101141219708
                                        )

                                )

                        )

                    [place_id] => ChIJVVVVVVUBDTkRhp3iuoJn_7w
                    [types] => Array
                        (
                            [0] => establishment
                            [1] => point_of_interest
                        )

                )

        )

    [status] => OK
)


Solutions(1)
	
	After json_decode();

	$state  = ($status=="OK")?$output->results[1]->address_components[6]->long_name:'';
        $city  = ($status=="OK")?$output->results[1]->address_components[3]->long_name:'';
        $streetaddress  = ($status=="OK")?$output->results[1]->address_components[0]->long_name:'';
        $pincode  = ($status=="OK")?$output->results[1]->address_components[8]->long_name:'';
                                    

< Regular Expression in php Export data to excel in php using mysql >



Ask a question



  • Question:
    {{questionlistdata.blog_question_description}}
    • Answer:
      {{answer.blog_answer_description  }}
    Replay to Question


Back to Top