批改状态:合格
老师批语:
$arr = array('a', 'b', 'c', 'd', 'e');//切割成每个小数组为两个的二维数组printf('<pre>%s</pre>', print_r(array_chunk($arr, 2), true));echo '<hr>';//切割的时候,原来的键值不变动printf('<pre>%s</pre>', print_r(array_chunk($arr, 2, true), true));
$array = array(1, "hello", 1, "world", "hello");printf('<pre>%s</pre>', print_r($array, true));printf('<pre>%s</pre>', print_r(array_count_values($array), true));//返回,键名变成了数组内的原来的值,值代表重复的次数Array([1] => 2[hello] => 2[world] => 1)
$array1 = array("color" => "red", 2, 4);$array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4);$result = array_merge($array1, $array2);printf('<pre>%s</pre>', print_r($result, true));
$array1 = array("a" => "green", "red", "blue");$array2 = array("b" => "green", "yellow", "red");$result = array_intersect($array1, $array2);printf('<pre>%s</pre>', print_r($result, true));
$input = array("php", 4.0, array("green", "red"));$reversed = array_reverse($input);$preserved = array_reverse($input, true);printf('<pre>%s</pre>', print_r($input, true));//打印原本的数组printf('<pre>%s</pre>', print_r($reversed, true));//把数组倒序,键名重置printf('<pre>%s</pre>', print_r($preserved, true));//把数组倒序,键名跟随之前的值,不改变
//array_fill(数组起始索引,插入元素的数量,用来填充的值)$b = array_fill(5, 6, 'banana');$c = array_fill(-2, 4, 'pear');printf('<pre>%s</pre>', print_r($b, true));printf('<pre>%s</pre>', print_r($c, true));
$keys = array('foo', 5, 10, 'bar');//array_fill_keys(使用该数组的值作为键,填充使用的值)$a = array_fill_keys($keys, 'banana');printf('<pre>%s</pre>', print_r($a, true));
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号