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:
<?php
$deck = new \Ds\Deque([1, 2, 3, 4, 5, 6]);
echo ( "Elements in the deque\n" );
var_dump( $deck );
echo ( "\nLast element in the deque: " );
var_dump( $deck ->last());
?>
|
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:
<?php
$deck = new \Ds\Deque([ "geeks" , "for" , "geeks" ]);
echo ( "Elements in the deque\n" );
print_r( $deck );
echo ( "\nLast element in the deque: " );
print_r( $deck ->last());
?>
|
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...