• PHP Video Tutorials

PHP - Ds Vector pop() Function



Ds\Sequence::pop() function can remove and return the last value.

Syntax

abstract public mixed Ds\Sequence::pop( void )

Ds\Sequence::pop() function doesn't have any parameters. This function can return the removed last value.

Ds\Sequence::pop() function can throw UnderflowException if empty.

Example 1

<?php 
   $array1 = new \Ds\Vector([10, 20, 30, 40, 50]); 
  
   echo("Original vector elements \n"); 
   print_r($array1); 
   
   echo("The last element in vector:"); 
  
   var_dump($array1->pop()); 
  
   echo("\n After removing the last element \n"); 
   print_r($array1);
?>

Example 2

<?php 
   $array1 = new \Ds\Vector(["Tutorials", "Point", "Tutiorix"]); 
     
   echo("Original vector elements \n"); 
   print_r($array1); 
  
   echo("The last element in vector:"); 
  
   var_dump($array1->pop()); 
  
   echo("\n After removing the last element \n"); 
   print_r($array1); 
?>
php_function_reference.htm
Advertisements