I have the following script:
$arr = [
10 => [
'Xa' => 'xA'
],
32 => [
'Xb' => 'xB'
],
45 => [
'Xc' => 'xC'
],
78 => [
'Xd' => 'xD'
]
]
foreach($arr as $var){
if($var['Xa'] == 'xA'){
//Nesta escapatória encontrar 'this' para modificar $arr[10]
}
}
- Can you find
'this'
withinif
without using'key'
?
The context of the question is that in a given loop (of a growing non-sequential array) I need to append data to this array, and I can not access its key because some unsets are given at the time of construction.
Previously it worked with this (before adding the unsets), but it is not working anymore and is adding keys that no longer exist in the array:
$c = 0;
foreach ($return as $rs_row) {
foreach ($rs_flag as $flag) {
if ($rs_row['id'] == $flag['relationship']) {
$return[$c]['flag'] = $flag['flag'];
$return[$c]['flag-cod'] = $flag['cod'];
$return[$c]['flag-observations'] = $flag['observations'];
}
}
$c += 1;
}