php8.5
Home/ Manual/ spl / arrayobject/ ArrayObject::offsetExists

ArrayObject::offsetExists

PHP function Edit on GitHub ✎

(PHP 5, PHP 7, PHP 8)

Returns whether the requested index exists

Description

ArrayObject::offsetExists(mixed $key): bool

Parameters

key

The index being checked.

Return Values

true if the requested index exists, otherwise false

Examples

ArrayObject::offsetExists example

php
<?php
$arrayobj = new ArrayObject(array('zero', 'one', 'example'=>'e.g.'));
var_dump($arrayobj->offsetExists(1));
var_dump($arrayobj->offsetExists('example'));
var_dump($arrayobj->offsetExists('notfound'));
?>

The above example will output:

output
bool(true)
bool(true)
bool(false)

Source: reference/spl/arrayobject/offsetexists.xml · from the official PHP manual (php/doc-en)