Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I select a range of indexes from an array?

Tags:

arrays

php

In python I would do this:

var = ["test","test1","test2","test3"];
test= var[1:3];

Then variable 'test' would be ["test1","test2","test3"]

How can I do this in PHP?

like image 705
Jeroen Avatar asked Dec 17 '10 13:12

Jeroen


1 Answers

That would be array_slice($var, 1, 3). See also: http://php.net/manual/en/function.array-slice.php.

Complete example:

$var = array("test","test1","test2","test3");
$test = array_slice($var, 1, 3);
like image 70
Spiny Norman Avatar answered Sep 19 '22 15:09

Spiny Norman