PHP.mk документација

SplDoublyLinkedList::valid

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

spldoublylinkedlist.valid.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека spldoublylinkedlist.valid.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
SplDoublyLinkedList::valid

Референца за `spldoublylinkedlist.valid.php` со подобрена типографија и навигација.

spldoublylinkedlist.valid.php

SplDoublyLinkedList::valid

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

SplDoublyLinkedList::validПроверете дали двојно поврзаната листа содржи повеќе јазли

= NULL

public SplDoublyLinkedList::valid(): bool

Проверува дали двојно поврзаната листа содржи повеќе јазли.

Параметри

Оваа функција нема параметри.

Вратени вредности

Патеката до PHP скриптата што треба да се провери. true ако двојно поврзаната листа содржи повеќе јазли, false otherwise.

Белешки од корисници 2 забелешки

phpdude на zootal точка com
пред 8 години
The docs say "Check whether the doubly linked list contains more nodes". I do not believe this is correct.

Example:

$dlist = new SplDoublyLinkedList;
$data=[1,2,3,4,5];

foreach($data as $d)
    $dlist->push($d);
$dlist->rewind();

for($i=0;$i<6;$i++)
{
    $currentValue = $dlist->current();
    $currentValid = $dlist->valid();

    $status = $currentValid ? 'True' : 'False';
    echo 'Current value is: ' . $currentValue . ' Valid status is: ' . $status . "\n";

    $dlist->next();
}

Output:

Current value is: 1 Valid status is: True
Current value is: 2 Valid status is: True
Current value is: 3 Valid status is: True
Current value is: 4 Valid status is: True
Current value is: 5 Valid status is: True
Current value is:  Valid status is: False

Note that when we are on the last node of the list, value = 5, the valid() function returns true. Yet we are on the last node of the list, and there are no more nodes. If the valid() function were checking to see if there were any more nodes on the list, it would return false, not true.

If you look at the docs for Iterator::valid, they say "Checks if current position is valid". I believe that is in fact what valid() does, it checks to see if the *current* position is valid, *not* if there are any more nodes.

Be aware of this or it will bite you. You can happily iterate to the end of the list, run valid(), think there is one more node, do a next(), grab the value, and you get null instead of the last node of the list.
Premysl Karbula
пред 8 години
$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]);
}

$a->rewind();

while($a->valid()){
    echo 'key ', $a->key(), ' value ', $a->current(),"\n";
    $a->next();
}
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.