Skip to content

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.

Uses Dot Notation?

No. Use array_has when you need to check deeply nested arrays.

Syntax:

mixed array_exists( 
     ArrayAccess|array $subjectArrayOrArrayAccess, 
     string|int $keyOrOffset
);

Example

$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

« Back to Array API

Clone this wiki locally