<?php
Class Car {
private $id;
public function __construct($id){
$this->id = $id;
}
public function getId(){
return $this->id;
}
}
$cars = [ new Car(3), new Car(4)];
$res = array_combine(
array_map(function ($o) {
return $o->getId();
}, $cars), $cars
);
//
array(2) {
[3]=>
object(Car)#1 (1) {
["id":"Car":private]=>
int(3)
}
[4]=>
object(Car)#2 (1) {
["id":"Car":private]=>
int(4)
}
}