-
Notifications
You must be signed in to change notification settings - Fork 1
array_exists
Tonya Mork edited this page Mar 12, 2017
·
2 revisions
The array_exists
function checks to see if the given key or offset exists in the provided array or array object. It works on an array
or ArrayAccess
as the subject.
No. Use array_has
when you need to check deeply nested arrays.
mixed array_exists(
ArrayAccess|array $subjectArrayOrArrayAccess,
string|int $keyOrOffset
);
$user = array(
'name' => 'Bob Jones',
'social' => array(
'twitter' => '@bobjones',
),
'languages' => array(
'php' => true,
'javascript' => true,
'ruby' => false,
),
);
if ( array_exists( $this->dataArray, 'name') ) {
// do something
}
// evaluates to true
if ( array_exists( $this->dataArray, 'social.twitter') ) {
// do something
}
// evaluates to false, as it does not use dot notation