1

I want to get the data from array inside array as per the below code :

{"address":"0x64890972513558cb4e4b4a7f8af48d892fd097b7","ETH":{"**balance**":0,"totalIn":0,"totalOut":0},"countTxs":0,"tokens":[{"**tokenInfo**":{"**address**":"0xad640689e6950b7453729a4686edb3fdfd754616","**name**":"CIChain","decimals":"18","symbol":"CIC","totalSupply":"3000000000000000000000000000","owner":"0xecb64b92ffb5179b47c87d2f105d6eeebb132c68","lastUpdated":1527246490,"issuancesCount":0,"holdersCount":31528,"**price**":false}

i'm using this steps but I couldn't continue :

    $address = "0x64890972513558cb4e4b4a7f8af48d892fd097b7"; //$_POST['address'];


$scan_url = 'https://api.ethplorer.io/getAddressInfo/'.$address.'?apiKey=freekey';
$scan_json = file_get_contents($scan_url);
$scan_array = json_decode($scan_json, true);
foreach($scan_array['tokens'] as $key => $eth) { 
    foreach($eth['tokenInfo'] as $key => $etth) {  

  echo $etth['name'];  
}}

I want to retrieve the marked date by stars ** into echo in php so how can I get the nested data.

1
  • try json_decode($json)->balance Commented May 25, 2018 at 12:51

1 Answer 1

1

According to your url given you need to change you code like below

$scan_array = json_decode($scan_json, true);
foreach($scan_array['tokens'] as $key => $eth) { 
    echo $eth['tokenInfo']["name"]. "\n";
}

Live demo

Second foreach is giving all element from tokenInfo so either no need to use inner foreach or to get all element no need to use like $etth['name'] this, only $etth will give is enough.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you it worked fine, what if I want to get the address which is in the beginning of the array {"address":"0x64890972513558cb4e4b4a7f8af48d892fd097b7","ETH": ....... }
Just use $scan_array["address"]
I got this error Warning: Invalid argument supplied for foreach() in C:\AppServ\www\Airdrop\scan.php on line 9

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.