Oihana PHP

hasAnyProperty.php

Table of Contents

Functions

hasAnyProperty()  : bool
Check if at least one of the given properties exists in the object.

Functions

hasAnyProperty()

Check if at least one of the given properties exists in the object.

hasAnyProperty(object $object, array<string|int, mixed> $properties[, bool $notNull = false ]) : bool

If $notNull is set to true, the property must also be non-null.

Parameters
$object : object

The object to inspect

$properties : array<string|int, mixed>

List of property names to check

$notNull : bool = false

Whether to check for non-null values (default: false)

Tags
example

Recursive compression

$doc = (object)
[
   'id'     => 123  ,
   'slogan' => null ,
];

$props = [ 'slogan' , 'description' ] ;

hasAnyProperty( $doc , $props ) ; // true  (because 'slogan' exists)
hasAnyProperty( $doc , $props , true ) ; // false (because 'slogan' is null)
author

Marc Alcaraz

since
1.0.0
Return values
bool

True if at least one property exists (and is not null if $notNull = true)


        
On this page

Search results