Answer the question
In order to leave comments, you need to log in
How to add value to array while iterating over it in foreach?
Hello, I have 2 arrays that need to be iterated over and compared with some of their values. If the value of the first = the value of the second, then you need to write a new value to the first array, under the new key (type). I've tried different ways and can't figure it out.
This option returns
Illegal offset type in
$oneArray = ;
$twoArray = ;
foreach ($oneArray as $one) {
foreach ($twoArray as $two) {
if($one['2'] == $two['bb']){
$oneArray[$one]['type'] = 'b';
}else{
$oneArray[$one]['type'] = 'c'
}
}
}
//должно получиться
$oneArray = ;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question