Answer the question
In order to leave comments, you need to log in
How to get "randomly generated" value of json array?
There is an array like
{"success":1,"return":
{
"236015091":{"status":0,"pair":"new","type":"one","amount":0.05,"rate":188.0},
"244806736":{"status":1,"pair":"old","type":"two","amount":0.3,"rate":25.0},
"244901138":{"status":0,"pair":"sold","type":"three","amount":30.5,"rate":0.7}
},
"stat":{"isSuccess":true,"serverTime":"00:00:00.0000564","time":"00:00:00.0426275","errors":null}}
Answer the question
In order to leave comments, you need to log in
Try like this:
$arr = json_decode($json, true);
foreach ($arr['result'] as $k => $in_arr) {
echo "Имя внутреннего элемента: {$k}<br>";
echo "Перебор вложенных элементов:<br>";
foreach ($in_arr as $in_k => $in_v) {
echo "{$in_k} => {$in_v} ";
}
echo "<br>";
echo "Только определенный элемент внутреннего массива:<br>";
echo $in_arr['pair'], "<br>";
}
$arr = json_decode($json, true);
echo "<pre>";
var_dump(array_keys($arr['result']));
echo "</pre>";
$obj = json_decode($data,true);
foreach($obj as $obj_array)
{
echo $obj_array;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question