0
$json_string = 'http://pubapi.cryptsy.com/api.php?method=marketdatav2';

$jsondata = file_get_contents($json_string);

I am new in php. Maybe its stupid question. But what is the easiest way to get lastestprice of all markets?

2
  • what your json looks like, if you post it would be helpful to see and suggest. Commented Jan 22, 2014 at 19:18
  • json can be seen in the url, but it's a pretty big one Commented Jan 22, 2014 at 19:24

2 Answers 2

1

Try

$decoded = json_decode($jsondata);
$latestprices = array();
foreach($decoded['return']['markets'] as $val) {
    $latestprices[$val['label']] = $val['lasttradeprice'];
}
Sign up to request clarification or add additional context in comments.

Comments

0

Use json_decode function to convert json string to array & traverse the array accordingly.

 $jsondata = file_get_contents($json_string);
 $array = json_decode($jsondata,true);
 foreach($array['return']['markets'] as $lprice) {
  $latest_price[$lprice['label']] = $lprice['lasttradeprice'];
}
 echo "<pre>";
 print_r($latest_price);
 echo "<pre>";

2 Comments

do you know how to use methods Method: getmarkets Inputs: n/a Outputs: Array of Active Markets label - Name for this market primary_currency_code - Primary currency code this for example
@user1761818 I didn't what actually you're asking.

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.