-1
$location = '{ latitude: (location tatitude), longitude: (location longitude), description: (location description) }';

$json = json_decode($location,true);

$locationlat = $json['latitude'];

I want to pull the latitude data in php. Blank data comes when I do it this way. How can I pull latitude and long data?

2 Answers2

-1

In your $location is not a valid JSON So json_decode return null.

try

$location = '{ latitude: "location tatitude", longitude: "location longitude", description: "location description" }';

-1

First, the JSON code is wrong. JSON should look like this:

{
     "fooString": "barString",
     "fooObject": {
          "barString": "Hello World"
     }
}

Now... When you do json_decode(), it makes an object and you shall therefore retrieve a value like this:

$json = json_decode($location);
$locationlat = $json->latitude;
Dharman
  • 30,962
  • 25
  • 85
  • 135
ThorBilsby
  • 69
  • 1
  • 6