略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: SplDoublyLinkedList::offsetUnset

2024-12-23

SplDoublyLinkedList::offsetUnset

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

SplDoublyLinkedList::offsetUnsetUnsets the value at the specified $index

说明

public SplDoublyLinkedList::offsetUnset(int $index): void

Unsets the value at the specified index.

参数

index

The index being unset.

返回值

没有返回值。

错误/异常

Throws OutOfRangeException when index is out of bounds or when index cannot be parsed as an integer.

add a noteadd a note

User Contributed Notes 1 note

up
1
marco dot paulo dot lopes at gmail dot com
11 years ago
When unsetting an offset, the element will be removed from the double linked list. So the following code:

<?php

$obj
= new SplDoublyLinkedList();

$obj->push(4);
$obj->push(5);
$obj->push(6);

$obj->offsetUnset(1);
echo
"Our Linked List:";
print_r($obj);

?>

Will output:

Our Linked List:SplDoublyLinkedList Object
(
    [flags:SplDoublyLinkedList:private] => 0
    [dllist:SplDoublyLinkedList:private] => Array
        (
            [0] => 4
            [1] => 5
            [2] => 6
        )

)
Our New Linked List:SplDoublyLinkedList Object
(
    [flags:SplDoublyLinkedList:private] => 0
    [dllist:SplDoublyLinkedList:private] => Array
        (
            [0] => 4
            [1] => 6
        )

Notice that the element with the index 2 has now the index 1. The original element with index 1 did not only had it's value unset but was also removed from the list.

官方地址:https://www.php.net/manual/en/spldoublylinkedlist.offsetunset.php

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