Syntax:mixed SplDoublyLinkedList::key (void)
Parameters:this function takes no parameters.
Return value:returns the index of the current node.The following programs illustrate the
functionS
plDoublyLinkedList::key()in PHP:
Program 1:
// Declare an empty SplDoublyLinkedList
$list
=
new
SplDoublyLinkedList;
// Use the SplDoublyLinkedList::add() function for
// add elements to SplDoublyLinkedList
$list
-> add (0, 30);
$list
-> add (1, 20);
$list
-> add (2, 30);
$list
-> add (3,
" Geeks "
);
$list
-> add (4,
’ G’
);
$list
->
rewind
();
// Use the SplDoublyLinkedList::key() function
// to get the key
var_dump (
$list
-> key());
// Use the next() function to enlarge
// index value
$list
-> next();
// Use the SplDoublyLinkedList::key() function
// to get the key
var_dump (
$list
-> key());
?>
Exit:int (0 ) int (1)
Program 2:
// Declare an empty SplDoublyLinkedList
$list
=
new
SplDoublyLinkedList();
// Use the SplDoublyLinkedList::push() function for
// add elements to SplDoublyLinkedList
$list
-> push (1);
$list
-> push (2);
$list
-> push (3);
$list
-> push (8);
$list
-> push (5);
$list
->
rewind
();
// Use the SplDoublyLinkedList::key() function
// to get the key
var_dump (
$list
-> key());
// Use the next() function to enlarge
// index value
$list
-> next();
$list
-> next();
$list
-> next();
// Use the SplDoublyLinkedList::key() function
// to get the key
var_dump (
$list
-> key());
?>
Exit:int (0 ) int (3)
Link: https://www .php.net / manual / en / spldoublylinkedlist.key.php