I've created a helper to organize the menus returned from the database so that it looks similar to a return of a native method of the framework I'm using. The code snippet that contains 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 But what's coming in the final variable is this In other words, he is overwriting the first position with the second, why is this happening? What's wrong with the code?