PHP 7.0.6 Released

SplFixedArray::offsetExists

(PHP 5 >= 5.3.0, PHP 7)

SplFixedArray::offsetExistsReturns whether the requested index exists

Description

public bool SplFixedArray::offsetExists ( int $index )

Checks whether the requested index index exists.

Parameters

index

The index being checked.

Return Values

TRUE if the requested index exists, otherwise FALSE

User Contributed Notes

depoemarc at swap dot fn dot ln dot googlemail dot com
10 months ago
It should be noted that offsetExists behaves like "offsetIsSet" rather than "offsetIsValid":

<?php
$arr
= new SplFixedArray(3);
var_dump($arr->offsetExists(1)); // false

$arr[1] = 42; // $arr->offsetSet(1, 42);
var_dump($arr->offsetExists(1)); // true

$arr[1] = null; // $arr->offsetSet(1, null);
var_dump($arr->offsetExists(1)); // true

unset($arr[1]); // $arr->offsetUnset(1);
var_dump($arr->offsetExists(1)); // false

var_dump($arr);
/*
object(SplFixedArray)[1]
  null
  null
  null
*/
?>
To Top