Get Nested Value

Safely get a nested property value from an object.

Code

General
$o = (array)$obj;
$result = array_reduce(explode('.', $path), fn($o, $k) => is_array($o) && isset($o[$k]) ? $o[$k] : null, $o);
return $result;

Parameters

Object to search

Dot-separated path to property

Server

More PHP Snippets