method hasDeepProp documentation in bbn\X
Check if an array or an object has the given property.
Example
$arr = [
'a' => ['d' => [], 'e'],
'b' => 'g',
'c' => 0
];
X::hasDeepProp($arr, ['a']);
// (bool) true
X::hasDeepProp($arr, ['a'], true);
// (bool) true
X::hasDeepProp($arr, ['a', 'd']);
// (bool) true
X::hasDeepProp($arr, ['a', 'd'], true);
// (bool) false
X::hasDeepProp($arr, ['a', 'e']);
// (bool) false
X::hasDeepProp($arr, ['b']);
// (bool) true
X::hasDeepProp($arr, ['b'], true);
// (bool) true
X::hasDeepProp($arr, ['b', 'g']);
// (bool) false
X::hasDeepProp($arr, ['c']);
// (bool) true
X::hasDeepProp($arr, ['c'], true);
// (bool) false
function($obj, array $prop_path, bool $check_empty = false)
{
array $prop_path,
bool $check_empty = false
): ?bool
{
$o =& $obj;
foreach ($prop_path as $p) {
if (is_array($o)) {
if (!\array_key_exists($p, $o)) {
return false;
}
if ($check_empty && !$o[$p]) {
return false;
}
$o =& $o[$p];
}
elseif (\is_object($o)) {
if (!\property_exists($o, $p)) {
return false;
}
if ($check_empty && !$o->$p) {
return false;
}
$o =& $o->$p;
}
else {
return false;
}
}
return true;
}
Check if an array or an object has the given property. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way
This website uses cookies to ensure you get the best experience on our website.
© 2011-2025
BBN Solutions