It is very easy to reduce the object path using variable property notation ($o->$p
):
$path="foo.bar";
echo array_reduce(explode('.', $path), function ($o, $p) { return $o->$p; }, $user);
This could easily be turned into a small helper function.
It is very easy to reduce the object path using variable property notation ($o->$p
):
$path="foo.bar";
echo array_reduce(explode('.', $path), function ($o, $p) { return $o->$p; }, $user);
This could easily be turned into a small helper function.