如何从阵列中选择一系列索引?

时间:2010-12-17 13:59:34

标签: php arrays

在python中我会这样做:

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

然后变量'test'将是[“test1”,“test2”,“test3”]

我如何在PHP中执行此操作?

1 个答案:

答案 0 :(得分:20)

那将是array_slice($var, 1, 3)。另见:http://php.net/manual/en/function.array-slice.php

完整示例:

$var = array("test","test1","test2","test3");
$test = array_slice($var, 1, 3);