method hasProp documentation in bbn\X

Check if an array or an object has the given property

Example

$arr = [ 'a' => 1, 'b' => '', 'c' => 0 ]; X::hasProp($arr, 'a'); // (bool) true X::hasProp($arr, 'b'); // (bool) true X::hasProp($arr, 'b', true); // (bool) false X::hasProp($arr, 'c'); // (bool) true X::hasProp($arr, 'c', true); // (bool) false X::hasProp($arr, 'd'); // (bool) false X::hasProp('string', 'd'); // null function($obj, string $prop, bool $check_empty = false) { if (is_array($obj)) { return \array_key_exists($prop, $obj) && (!$check_empty || !empty($obj[$prop])); } elseif (is_object($obj)) { return \property_exists($obj, $prop) && (!$check_empty || !empty($obj->$prop)); } return null; }

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.