slicing syntax sugar
Posted by PHPVote 9 years ago
Sometimes, when we use arrays, we want to take some cols by using array_slice.
Something quite readable and more easy to write could be
$array = [1,2,3,4,5,6,7,8,9];
$slice = $array[1:]; //we take from col 1 to end
$slide2 = $array[1:4];//from col 1 to col 4
$slide3 = $array[1:20];//error !
It can be useful when we use func_get_args() and we want to get rid of the first arg or any collection manipulation. It is the same usecase as array_slice but shorter.