SplDoublyLinkedList::offsetUnset

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

SplDoublyLinkedList::offsetUnset — æŒ‡ćźšă—ăŸ $index た怀を扊陀する

èȘŹæ˜Ž

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

æŒ‡ćźšă—ăŸă‚€ăƒłăƒ‡ăƒƒă‚Żă‚čăźć€€ă‚’ć‰Šé™€ă—ăŸă™ă€‚

ăƒ‘ăƒ©ăƒĄăƒŒă‚ż

index

ć‰Šé™€ă—ăŸă„ă‚€ăƒłăƒ‡ăƒƒă‚Żă‚č。

æˆ»ă‚Šć€€

ć€€ă‚’èż”ă—ăŸă›ă‚“ă€‚

ă‚šăƒ©ăƒŒ / äŸ‹ć€–

index が範ć›Čć€–ă‚’æŒ‡ă™ăšăă‚„ index ăŒæ•Žæ•°ăšă—ăŠè§Łé‡ˆă§ăăȘă„ăšăă« OutOfRangeException をă‚čăƒ­ăƒŒă—ăŸă™ă€‚

add a note

User Contributed Notes 1 note

up
0
marco dot paulo dot lopes at gmail dot com ¶
15 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.