- array_map: documentation ( source)
- var_dump: documentation ( source)
<?php
$o1 = new stdClass();
$o1->id = 123;
$o1->title = 'test';
$o2 = new stdClass();
$o2->id = 456;
$o2->title = 'test2';
$arrofobjects = [
$o1,$o2
];
var_dump($arrofobjects);
$newArr = array_map(function($obj) {
return [$obj->id => $obj->title];
}, $arrofobjects);
var_dump($newArr);