php - Array of objects bug with index -
i have foreach :
foreach($values $key => $value){ $name = $value['name']; if(!isset($array[$value['position']])){ $array[$value['position']] = new \stdclass(); } $array[$value['position']]->$name = $value['value']; }
so in loop, in $value
, have $name
, $position
, $value
.
- $name name of property
- $value value
- $position position of object in array (index)
in loop, check first in object created in specific index (position), if not create it, , after put value in correct property.
my problem is, if in array of value don't have positions following (0,1,2,3) example (0,1,3,4), script bug , don't have correct array @ end.
how can detect if miss index ? , how can fix ?
thanks !
ps : don't know if have enough informations.. tell me !
edit :
at end, correct output must :
[object { name="d", complet="false"}, object { adresse="d", complet="false"}]
but, if script bug index, have :
object { 0={...}, 1={...}, 2={...}, plus...}
Comments
Post a Comment