CakeFest 2024: The Official CakePHP Conference

SplFixedArray::offsetExists

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

SplFixedArray::offsetExists指定した添字が存在するかどうかを返す

説明

public SplFixedArray::offsetExists(int $index): bool

index で指定した添字が存在するかどうかを返します。

パラメータ

index

調べたい添字。

戻り値

指定した添字が存在する場合に true、それ以外の場合に false を返します。

add a note

User Contributed Notes 1 note

up
4
depoemarc at swap dot fn dot ln dot googlemail dot com
8 years 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