1

I have this JSON string

{"ticker":{"high":736.45099,"low":681,"avg":708.725495,"vol":13038780.63684,"vol_cur":18382.55965,"last":726,"buy":726,"sell":724.5,"updated":1388242741,"server_time":1388242743}}

How can i get the "last" parameter after doing json_decode()?

1
  • 1
    $jsonArray = json_decode('...', true) echo $jsonArray['ticker']['last']; Commented Dec 28, 2013 at 15:21

2 Answers 2

6

Do like this

<?php
$json='{"ticker":{"high":736.45099,"low":681,"avg":708.725495,"vol":13038780.63684,"vol_cur":18382.55965,"last":726,"buy":726,"sell":724.5,"updated":1388242741,"server_time":1388242743}}';
$json_arr=json_decode($json,true);
echo $json_arr['ticker']['server_time'];//"prints" 1388242743 which is the last param "server time"
Sign up to request clarification or add additional context in comments.

2 Comments

Actually, the op asked about getting the parameter called "last". Other than that, this answer is the right one.
I too thought in a similar way and hence my comment. +1 anyway. :)
1

Use json_decode with parameters json string and TRUE.When TRUE, returned objects will be converted into associative arrays.

<?php
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';     
var_dump(json_decode($json, true));    
?>

http://php.net/json_decode

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.