• PHP Video Tutorials

PHP - Ds Vector slice() Function



Ds\Vector::slice() function can return a sub-vector of the given range.

Syntax

public Ds\Vector Ds\Vector::slice( int $index [, int $length ] )

Ds\Vector::slice() function can create a sub-vector of the given range.

Example 1

<?php   
   $vector = new \Ds\Vector([1, 2, 3, 4, 5]);  
   echo("The original vector: \n");   
   var_dump($vector);  
   
   $result = $vector->slice(1, 2); 
   echo("\n The new sub-vector: \n");  
   var_dump($result);   
?>

Example 2

<?php 
   $vector = new \Ds\Vector([1, 2, 3, 4, 5]); 
   echo("The original vector: \n"); 
   var_dump($vector); 
  
   $result = $vector->slice(2, -2); 
   echo("\n The new sub-vector: \n"); 
   var_dump($result); 
   
   $result = $vector->slice(4); 
   echo("\n The new sub-vector: \n"); 
   var_dump($result);
?>
php_function_reference.htm
Advertisements