Jump to content

Error working with Object array nested inside a json

Recommended Posts

Hello everyone.

please I have problem with printing out a value from inside an array of a nested json. ive tried several ways its always returns "index not define".
here is the code .

$valr= "https://ice3.com/api/v1/orderbook/ticker";    ////////////////////////////source

	 $valrGet =  file_get_contents($valr);
	 $valrD =  json_decode($valrGet, true);
	 $valrSell = ["ask"] ["price"];

Here is the structure of the json from the source :


my target is to  output  the value of  ("price") from "pair_name"   BTC\/ZAR

please help. Thanks in advance

Link to post
Share on other sites

However, using the string just as far as the the first entity

$valrD = json_decode(valrGet, true);
echo '<pre>$valrD = ', print_r($valrD, 1), '</pre>';




$target = 'BTC/ZAR';

foreach ($valrD['response']['entities'] as $k => $ents) {
    if ($ents['pair_name'] == $target) {
        echo "$target asking price : {$ents['ask']['price']}<br>";

outputs "BTC/ZAR asking price : 179382.54"


  • Like 1
  • Great Answer 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.