略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: SplDoublyLinkedList::top

2024-12-23

SplDoublyLinkedList::top

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

SplDoublyLinkedList::topPeeks at the node from the end of the doubly linked list

说明

public SplDoublyLinkedList::top(): mixed

参数

此函数没有参数。

返回值

The value of the last node.

错误/异常

Throws RuntimeException when the data-structure is empty.

add a noteadd a note

User Contributed Notes 1 note

up
-4
lincoln dot du dot j at gmail dot com
4 years ago
$a = new SplDoublyLinkedList;
$arr=[1,2,3,4,5,6,7,8,9];

for($i=0;$i<count($arr);$i++){
    $a->add($i,$arr[$i]);
}

echo "SplDoublyLinkedList array last/top value " .  $a->top() ." \n";
echo "SplDoublyLinkedList array first/top value " . $a->bottom() . " \n\n";

print_r($a);

//Another Example
$spl = new SplDoublyLinkedList;

$spl->push(11);
$spl->push(2);
$spl->push(3);
$spl->push(8);
$spl->push(5);

//array last value
echo $spl->top();
echo PHP_EOL;
//Array first value
echo $spl->bottom();
echo PHP_EOL;

print_r($spl);

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

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