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()?

Shankar Narayana Damodaran
68.6k43 gold badges102 silver badges129 bronze badges
asked Dec 28, 2013 at 15:19
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"
answered Dec 28, 2013 at 15:21
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

answered Dec 28, 2013 at 15:22

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.