I have the following code:
foreach($foo as $n=>$ia) {
foreach($ia as $i=>$v) {
$bar[$i]->$n = $v;
}
}
If I add:
$bar[$i] = new stdClass;
$bar[$i]->$n = $v;
to fix it. Then the values in the objects in the array "bar" are not specified. For example, I have an array:
$foo = array(
"somefield" => array("value1", "value2", "value3"),
"anotherfield" => array("value1", "value2", "value3")
);
At the output, I should get:
$bar[0]->somefield = value1
$bar[1]->anotherfield = value2
But in practice, I get:
$bar[0]->somefield = null
$bar[1]->anotherfield = null
How do I update the code to make it work?
Pasaf source
share