0

I am fairly new to handling strings and arrays I was wondering if someone could help.

I am using the following; file_get_contents()

$xml = file_get_contents("https://explorer.casinocoin.org/ext/getaddress/c4fpX7druW1JfgveFq6e7WabveVkAvW7gj");

which returns the following output;

{"address":"WALLET ADDRESS","sent":0,"received":1110,"balance":"BALANCE AMOUNT","last_txs":[{"type":"vout","addresses":"EXAMPLE 1"},{"addresses":"EXAMPLE 2","type":"vout"},{"addresses":"EXAMPLE 3","type":"vout"},{"addresses":"EXAMPLE 4","type":"vout"}]}

I have tried looking to foreach and also explode() however I can't get these to work. I need to be able to define the addresses in the output so I can reference them later.

I am not sure how I would implement a foreach into this example and define the address; I need it to perform like the following;

foreach addresses {

$addresses = 'Example 1';

}

and the next cyle would be;

foreach addresses {

$addresses = 'Example 2';

}

I do apologize for asking for help I'm just having great difficulty defining these values ; I also wasn't sure if I needed to convert this string into an array instead.

  • 1
    it's a valid json string, there's a built-in function for that already, it's called `json_decode`. don't use `explode` – Kevin Nov 30 '20 at 02:39
  • ah right that makes sense i will take a look at that thankyou very much –  Nov 30 '20 at 02:39
  • @Kevin would i put something like this within a foreach then? `$obj = json_decode($xml); print $obj->{'addresses'};` –  Nov 30 '20 at 02:41
  • 1
    no, there's a sub level you need to point first, `foreach ($obj->last_txs as $value) { echo $value->addresses; }` – Kevin Nov 30 '20 at 02:43

0 Answers0