2
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]
}
}
- It is possible to find
'this'
insideif
unused'key'
?
The context of the question is that in a given loop (from a nonsequential ascending array) I need to add data to this array, and I cannot access its key because some unsets are given at the time of construction.
It previously worked with this (before adding the unsets), but is no longer working 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;
}
Already asked this here. I think it was Wallace. I’ll look. Only the "focus" was to rescue the content in a loop...
– Jefferson Quesado
@Jeffersonquesado knows the link to this question ? I just thought to find the Dice, I can’t/I don’t want this because the indexes are scrambled, I need to somehow find 'this' or redo the part that builds this array so that it keeps the sequence.
– AnthraxisBR
It might help: https://answall.com/a/154082/64969; not exactly a duplicate, I was wrong... but it shows how to transform a
array
in a key/value pair, which I believe is positive for your case– Jefferson Quesado
you want to take the Input of the current element?
key()
orarray_keys()
do not help?– rray