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":[]}}
Ognjen Babic
  • 131
  • 16
Hajana
  • 15
  • 6
  • `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. – Marc B Feb 09 '16 at 19:52

1 Answers1

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;
maxhb
  • 8,554
  • 9
  • 29
  • 53
  • If the answer solved your problem you should strongly consider to accept that answer, as describeb in http://meta.stackexchange.com/questions/23138/how-to-accept-the-answer-on-stack-overflow – maxhb Feb 10 '16 at 06:31