I have a foreach like :
foreach($values as $key => $value){
$name = $value['name'];
if(!isset($array[$value['position']])){
$array[$value['position']] = new \stdClass();
}
$array[$value['position']]->$name = $value['value'];
}
So in my loop, in $value
, I have $name
, $position
and $value
.
- $name is the name of the property
- $value is the value
- $position is the position of the object in the array (index)
In this loop, i check first in my object is already created in the specific index (position), if not i create it, and after i put the value in the correct property.
My problem is, if in my array of value i don't have all the positions following (0,1,2,3) but for example (0,1,3,4), my script bug and i don't have the correct array at the end.
How can i detect if i miss an index ? And how can i fix this ?
Thanks for help !
PS : I don't know if you have enough informations.. tell me !
EDIT :
At the end, the correct output must be :
[Object { name="d", complet="false"}, Object { adresse="d", complet="false"}]
But, if the script bug with the index, i have :
Object { 0={...}, 1={...}, 2={...}, plus...}