一维数组取一部分

array_slice() 函数在数组中根据条件取出一段值,并返回。

 1 <!DOCTYPE html>
 2 <html>
 3 <body>
 4 
 5 <?php
 6 $a=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow","e"=>"brown");
 7 print_r(array_slice($a,1,2));
 8 
 9 $a=array("0"=>"red","1"=>"green","2"=>"blue","3"=>"yellow","4"=>"brown");
10 print_r(array_slice($a,1,2));
11 ?>
12 
13 </body>
14 </html>

结果

1 Array ( [b] => green [c] => blue ) 
2 Array ( [0] => green [1] => blue ) 

出处:http://www.w3school.com.cn/php/func_array_slice.asp

posted @ 2017-09-08 15:03  万里冰封  阅读(622)  评论(0编辑  收藏  举报