Answer the question
In order to leave comments, you need to log in
PHP How to run two JSON arrays through one Foreach?
Welcome all!
There are two different arrays that do not resemble each other in any way. I run them through foreach:
foreach($arr['value'] as $key=>$val){
//Выполнение начального кода
foreach($arr2['value'] as $key=>$val2){
//выполнение кода во втором цикле
}
//Выполнение последующего кода
}
Answer the question
In order to leave comments, you need to log in
There are several options.
1. pull out all the keys from the first and from the second into arrays. and then banal enumeration
$keys1 = подставьте тут сами;)
$keys2 = и тут ;)
for ( $k=0; $k < count($keys1) && $k < count($keys2); $k++)
{
$value_from_arr1 = $arr['value'][$keys1[$k]];
$value_from_arr2 = $arr2['value'][$keys2[$k]];
// do stuff
}
function from_arr(&$arr)
{
//
}
while ( ($value1 = from_arr($arr1))!==null && ($value2 = from_arr($arr2))!==null)
{
// do_stuff
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question