0

How can i get ID value only?

like so here: $fo = "11890408";

  {"success":true,"result":{"success":[{"id":"11890408","device_id":"17183","message":"okey","status":"pending","send_at":1455046054,"queued_at":0,"sent_at":0,"delivered_at":0,"expires_at":1455049654,"canceled_at":0,"failed_at":0,"received_at":0,"error":"","created_at":1455046054,"contact":{"id":"2522330","name":"923336458112","number":"923336458112"}}],"fails":[]}}
1
  • json_decode(), then you end up with a plain old php data structure, and access anything in it like you would with any OTHER php data structure. Commented Feb 9, 2016 at 19:52

1 Answer 1

1

Convert the json string to a php data structure and then navigate through the data tree of objects and arrays:

$json = '{
  "success":true,
  "result":{
    "success[
      {
        "id":"11890408",
        "device_id":"17183",
        "message":"okey",
        "status":"pending",
        "send_at":1455046054,
        "queued_at":0,
        "sent_at":0,
        "delivered_at":0,
        "expires_at":1455049654,
        "canceled_at":0,
        "failed_at":0,
        "received_at":0,
        "error":"",
        "created_at":1455046054,
        "contact":{
          "id":"2522330",
          "name":"923336458112",
          "number":"923336458112"
        }
      }
    ],
    "fails":[]
  }
}';

$data = json_decode($json);
$fo = $data->result->success[0]->id;
Sign up to request clarification or add additional context in comments.

1 Comment

If the answer solved your problem you should strongly consider to accept that answer, as describeb in meta.stackexchange.com/questions/23138/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.