略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: SplFixedArray::offsetExists

2024-11-22

SplFixedArray::offsetExists

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

SplFixedArray::offsetExistsReturns whether the requested index exists

说明

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

Checks whether the requested index index exists.

参数

index

The index being checked.

返回值

true if the requested index exists, otherwise false

add a noteadd a note

User Contributed Notes 1 note

up
3
depoemarc at swap dot fn dot ln dot googlemail dot com
6 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
*/
?>

官方地址:https://www.php.net/manual/en/splfixedarray.offsetexists.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3