PHP数组函数
<?php
//1.计算数组中所有值的乘积array_product
$a = array(1, 2, 3, 4);
echo "product(a) = " . array_product($a);
echo "<br><br>";
//2.从数组中随机取出一个或多个单元array_rand
$input = array("a", "b", "c", "d", "e");
$rand_keys = array_rand($input, 2);
echo $input[$rand_keys[0]];;
echo "<br>";
//3.将数组最后一个单元移除数组array_pop
$stack = array("0", "1", "2", "3","4");
$fruit = array_pop($stack);
var_dump($stack);
echo "<br>";
//4.在数组开头插入一个或多个单元array_unshift
$queue = array("1", "2");
array_unshift($queue, "3", "4");
var_dump($queue);
echo "<br>";
//5.将一个或多个单元压入数组的末尾(入栈)array_push
$stack = array("1", "2");
array_push($stack, "3", "4");
var_dump($stack);
echo "<br>";
//6.计算数组中所有值的和array_sum
$a = array(2, 4, 6, 8);
echo "sum(a) = ".array_sum($a);
echo "<br>";
$b = array("a" => 1.1, "b" => 1.2, "c" => 1.3);
echo "sum(b) = " . array_sum($b);
echo "<br>";
//7.移除数组中重复的值array_unique
$input = array(4, 4, "3", 4, 3, "3",1,1,1,2,3,5,4,2,3);
$result = array_unique($input);
var_dump($result);
echo "<br>";
//8.对数组进行排序并保持索引关系asort
$fruits = array( "b", "a", "z", "d");
asort($fruits);
var_dump($fruits);
echo "<br>";
//9.对数组进行逆向排序并保持索引关系arsort
$fruits = array( "b", "a", "z", "d");
arsort($fruits);
var_dump($fruits);
echo "<br>";
//10.键名的正序对数组进行排序ksort
$fruits = array( "b", "a", "z", "d");
ksort($fruits);
var_dump($fruits);
$fruits = array( "b"=>"b", "a"=> "a", "z"=>"z", "d"=>"d");
ksort($fruits);
var_dump($fruits);
echo "<br>";
//11.键名的倒序对数组进行排序krsort
$fruits = array( "b", "a", "z", "d");
krsort($fruits);
var_dump($fruits);
$fruits = array( "b"=>"b", "a"=> "a", "z"=>"z", "d"=>"d");
krsort($fruits);
var_dump($fruits);
echo "<br>";
//12.键值的正序对数组进行排序sort
$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);
var_dump($fruits);
echo "<br>";
//13.键值的倒序对数组进行排序rsort
$fruits = array("lemon", "orange", "banana", "apple");
rsort($fruits);
var_dump($fruits);
echo "<br>";
//14.把数组中的值赋给一些变量list
$a=array(18,20,25);
list($zhangsan,$lisi,$wangwu)=$a;
echo $zhangsan;
echo"<br>";
echo $lisi;
echo"<br>";
echo $wangwu;
?>