0

I have the following code below, which I am trying to run to save the key in the json to a PHP varible. However, for some reason it's just not doing anything - although it seems my code is right, any ideas where I am going wrong?

<?php
$json = file_get_contents('url');
$data = json_decode($json,true);

$id = $data['s_id'];


echo($id);

?>

and the json from the external URL looks like this

[{"s_id":"20063"}]
2
  • 3
    $data[0]['s_id'] Commented Sep 8, 2016 at 17:38
  • 1
    You can always use print_r($data); to see the parsed data. Commented Sep 8, 2016 at 17:52

1 Answer 1

4

You have an array wrapping the object

$id = $data[0]['s_id'];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.