我想获得由原始数组$arr
的前4
行组成的数组,
在PHP中如何实现?
看这个...应该会有所帮助
<?php
$input = array("a", "b", "c", "d", "e");
$output = array_slice($input, 2); // returns "c", "d", and "e"
$output = array_slice($input, -2, 1); // returns "d"
$output = array_slice($input, 0, 3); // returns "a", "b", and "c"
// note the differences in the array keys
print_r(array_slice($input, 2, -1));
print_r(array_slice($input, 2, -1, true));
?>
array_search()
这样的函数......但这完全取决于您需要做什么,并且是一个完全不同的问题。 - Mark Baker