Related Articles

Related Articles

PHP | Ds\Deque last() Function
  • Last Updated : 14 Aug, 2019

The Ds\Deque::last() function is an inbuilt function in PHP which is used to return the last element of Deque if Deque is not empty.

Syntax:

public Ds\Deque::last( void ) : mixed

Parameters: This function does not accept any parameter.

Return Value: This function returns the last element in the deque if it is not empty.

Exception: This function throws UnderflowException if the Deque is empty.



Below programs illustrate the Ds\Deque::last() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a Deque
$deck = new \Ds\Deque([1, 2, 3, 4, 5, 6]);
  
echo("Elements in the deque\n");
  
// Display the Deque Elements
var_dump($deck);
  
echo("\nLast element in the deque: ");
  
// Use last() function to display the 
// last element from the deque
var_dump($deck->last());
  
?>

chevron_right


Output:

Elements in the deque
object(Ds\Deque)#1 (6) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  int(4)
  [4]=>
  int(5)
  [5]=>
  int(6)
}

Last element in the deque: int(6)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a Deque
$deck = new \Ds\Deque(["geeks", "for", "geeks"]);
  
echo("Elements in the deque\n");
  
// Display the Deque Elements
print_r($deck);
  
echo("\nLast element in the deque: ");
  
// Use last() function to display the 
// last element from the deque
print_r($deck->last());
  
?>

chevron_right


Output:

Elements in the deque
Ds\Deque Object
(
    [0] => geeks
    [1] => for
    [2] => geeks
)

Last element in the deque: geeks

Reference: http://php.net/manual/en/ds-deque.last.php




My Personal Notes arrow_drop_up
Recommended Articles
Page :