// Create an ArrayObject $arrayObj = new ArrayObject(['foo' => 'bar', 'baz' => 'qux']); // Check if offset exists if ($arrayObj->offsetExists('foo')) echo 'Offset exists!'; else echo 'Offset does not exist.';
// Create an ArrayObject $arrayObj = new ArrayObject(['apple', 'orange', 'banana']); // Check if offset exists if ($arrayObj->offsetExists(3)) echo 'Offset exists!'; else echo 'Offset does not exist.';This code will output `Offset does not exist.` because the offset `3` does not exist in the array. The `ArrayObject` class is a part of the PHP core library, so no external package needs to be installed to use this method.