0

I have the following format of response from using curl:

{
    "result": {
        "total": 1,
        "userquery": "my own query",
        "items": [
            {
                "coord": {
                    "a": -326.9159528,
                    "b": 12.0192037
                }
            }
        ]
    }
}

I want to save the parts after "a": and "b": so only the two sets of number will be saved in php variables.

How can I do it? And what would be the best way of doing it?

D Kim
  • 97
  • 1
  • 1
  • 11

1 Answers1

4

The data you have received is JSON. You will need to decode the data using json_decode() and then access the variables:

$data = json_decode($curl_response);

$a = $data->result->items[0]->coord->a;
$b = $data->result->items[0]->coord->b;

Example/Demo

Darren
  • 13,050
  • 4
  • 41
  • 79