6、array_slice
复制代码 代码示例:
<?php
/*
array_slice 作用为切割数组,第三个参数为要切割的长度,如果省略则切割到数组的末尾
第四个参数默认为True,设置为False只对KEY为数字的数组起作用——即重新排列数组key,
索引从0-N
*/$arr = array(“zhejiang” => “浙江”, “jiangsu” => “江苏”, “anhui” => “安徽”,
“shagnhai” => “上海”, “nanjing” => “南京”, “hefei” => “合肥”);$tmp = array_slice($arr, 0, 5);
print_r($tmp);
echo “<hr/>”;
#################################################################
$arr = array( 999=>1, 10000=>2,4,5,6,7,8,9);$tmp = array_slice($arr, 0, 5, True);
print_r($tmp);
echo “<hr/>”;$tmp = array_slice($arr, 0, 5, False);
print_r($tmp);
echo “<hr/>”;
#################################################################
$arr = array(“zhejiang” => “浙江”, “jiangsu” => “江苏”, “anhui” => “安徽”,
“shagnhai” => “上海”, “nanjing” => “南京”, “hefei” => “合肥”);$tmp = array_slice($arr, -4, 2);
print_r($tmp);
echo “<hr/>”;
/* www.jb200.com
Array
(
[anhui] => 安徽
[shagnhai] => 上海
)
*/?>
7、array_sum
复制代码 代码示例:
<?php
$arr = array(’1′, ’100′);echo array_sum($arr); //101
echo “<hr/>”;$arr = array(‘a’, ’100′);echo array_sum($arr); //100
echo “<hr/>”;$arr = array(’11a’, ’100′);echo array_sum($arr); //111
echo “<hr/>”;
?>
8、extract
复制代码 代码示例:
<?php
$arr = array(“a1″ => 1, ‘b’ => 2);extract($arr);echo $a1;
echo $b;?>
9、list
复制代码 代码示例:
<?php
/*
输出连续键值(键值必须为数字字面量)的数组值,并分配给前面的变量
数字字面量必须从0开始
*/$arr = array(’0′=>1, ’1′=>2);list($first, $second) = $arr;echo $first;
echo $second;?>
10.array_combine
复制代码 代码示例:
<?php
$a = array('green', 'red', 'yellow');$b = array('avocado', 'apple', 'banana'); $c = array_combine($a, $b);print_r($c);?>//上例将输出:Array( [green] => avocado [red] => apple [yellow] => banana)
#Php