0
I created a helper to organize the menus returned from the database in a way that is similar to a return of a native method of the framework I am using. The code snippet containing the error is this:
$obj = new \stdClass;
$menu = array();
for($i=0; $i<count($menus_aceitos_name); $i++){
$obj->name = $menus_aceitos_name[$i];
$obj->id = $menus_aceitos_id[$i];
$menu[$i] = $obj;
}
I debugged and the expected result would be this But what’s coming in the final variable is this In other words, he’s overwriting the first position with the second, why is this happening? What’s wrong with the code?