For example, I have objects:
<?php
class A
{
public $key;
public $parent;
}
class B
{
public $value;
public $objects;
}
$a1 = new A();
$a1->key = 'a1';
$a2 = new A();
$a2->key = 'a2';
$a2->parent = $a1;
$a3 = new A();
$a3->key = 'a3';
$a3->parent = $a2;
$b = new B();
$b->objects = [$a1, $a2, $a3];
$b->value = 100;
someFunction($b);
In result I need to get array like this:
[
'a1' => ['a2' => ['a3' => 100]]
]
How can I build this array? Of Course 3 objects is just an example, this value may be bigger or smaller, so I need recursive function I think.