Having the following array,
$dataset = [
['item1' => 'value1'],
['item2' => 'value2'],
['item3' => 'value3'],
];
I need to convert it to this stdClass
object
$dataset = [
'item1' => 'value1',
'item2' => 'value2',
'item3' => 'value3',
];
In order to do that, I use these nested foreach
$object = new stdClass;
foreach ($dataset as $item) {
foreach ($item as $key => $value) {
$object->{$key} = $value;
}
}
// At this point $object is the expected output
I look for a better way to do it, one in which I can avoid foreach nesting
The final expected output is
stdClass Object
(
[item1] => value1
[item2] => value2
[item3] => value3
)
Thanks for your suggestions.