Answer the question
In order to leave comments, you need to log in
How to properly write conditions for Json?
Есть файл json { "streams" : {
"stream1": { "alive" : 0, "iframe" : "url" },
"stream2": { "alive" : 0, "iframe" : "url" },
....
"stream8": { "alive" : 0, "iframe" : "url" },
} }
как правильно написать условия что бы когда все alive = 0 вывелось содержимое
сделал такт но что-то не то
if ($json->alive[0-8] == 0 ) {
echo '1';
}
Подскажите плиз.
Answer the question
In order to leave comments, you need to log in
$sJson = '{"streams":{"stream1":{"alive":0,"iframe":"url" },"stream2":{"alive":0,"iframe":"url"},"stream8":{"alive":0,"iframe":"url"}}}';
$rgJson = json_decode($json, true);
$allDead = true;
foreach($rgJson['streams'] as $stream) {
if ($stream['alive'] != 0) {
$allDead = false;
break;
}
}
if ($allDead) {
echo '1';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question