<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> array_slice.php </title>
<meta charset="UTF-8">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head> <body>
<?php
$input = array("a", "b", "two"=>"c", "d", "e");
var_dump($input);
echo '<hr><hr><hr>';
$output = array_slice($input, 2); // 返回 "c", "d", and "e"
echo '<hr><hr><hr>';
var_dump($output);
echo '<hr><hr><hr>';
$output = array_slice($input, -2, 1); // 返回 "d"
echo '<hr><hr><hr>';
var_dump($output);
echo '<hr><hr><hr>';
$output = array_slice($input, 0, 3); // 返回 "a", "b", and "c"
echo '<hr><hr><hr>';
var_dump($output);
echo '<hr><hr><hr>';
// 输出部分数组成员,注意数组索引同原始数组索引的变化
print_r(array_slice($input, 2, -1));//Array ( [two] => c [0] => d ) //更新数字索引
echo "<hr>";
//设定preserve_keys 参数为true,保证数组索引和原来数组一致
//即元素c,d 在input 中索引为two 和3,则新数组索引一样为two 和3
print_r(array_slice($input, 2, -1, true));//Array ( [two] => c [2] => d ) //保存原始数字索引
echo "<br>";
?>
</body>
</html>
array
0 => string 'a' (length=1)
1 => string 'b' (length=1)
'two' => string 'c' (length=1)
2 => string 'd' (length=1)
3 => string 'e' (length=1)
array
'two' => string 'c' (length=1)
0 => string 'd' (length=1)
1 => string 'e' (length=1)
array
0 => string 'd' (length=1)
array
0 => string 'a' (length=1)
1 => string 'b' (length=1)
'two' => string 'c' (length=1)
Array ( [two] => c [0] => d )
Array ( [two] => c [2] => d )
array_slice.php
转载
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
array auto slice
array auto slice
array auto slice slice Array i++ javascript