批改状态:合格
老师批语:
$arr = ['id' => 1, 'name' => '赵大', 'email' => 'zhaoda@qq.com', 'hello', 'php', 'js'];printf('原数组: <pre>%s</pre>', print_r($arr, true));echo '<hr>';// 1.array_rand(数组,要取出的单元数量): 从数组中随机取出一个或多个随机键printf('1.随机取出键名: <pre>%s</pre>', print_r(array_rand($arr, 3),true));

$arr = ['id' => 1, 'name' => '赵大', 'email' => 'zhaoda@qq.com', 'hello', 'php', 'js'];printf('原数组: <pre>%s</pre>', print_r($arr, true));echo '<hr>';// 2.array_flip(数组)printf('2.交换数组中的键和值: <pre>%s</pre>', print_r(array_flip($arr),true));

// 3.array_diff(数组): 计算数组的差集$array1 = array("a" => "green", "red", "blue", "red");$array2 = array("b" => "green", "yellow", "red");printf('数组1: <pre>%s</pre>', print_r($array1,true));printf('数组2: <pre>%s</pre>', print_r($array2,true));// 数组$array1中的值与数组$array2中的值做对比,返回$array2中没有$array1中的值$result = array_diff($array1, $array2);printf('数组1与数组2的差集: <pre>%s</pre>', print_r($result,true));

//4.array_combine(): 创建一个数组,用一个数组的值作为其键名,另一个数组的值作为其值$arr1 = ['id', 'name', 'email'];$arr2 = [1, '赵大', 'zhaoda@qq.com'];printf('数组1: <pre>%s</pre><hr>', print_r($arr1, true));printf('数组2: <pre>%s</pre><hr>', print_r($arr2, true));$result = array_combine($arr1, $arr2);printf('用一个数组的值作为其键名,另一个数组的值作为其值: <pre>%s</pre>', print_r($result, true));

// 5.array_intersect(): 计算数组的交集$array1 = array("a" => "green", "red", "blue", "red");$array2 = array("b" => "green", "yellow", "red");printf('数组1: <pre>%s</pre>', print_r($array1,true));printf('数组2: <pre>%s</pre>', print_r($array2,true));$result = array_intersect($array1, $array2);printf('数组1与数组2的交集: <pre>%s</pre>', print_r($result,true));

// 6.array_reverse(): 返回单元顺序相反的数组$arr = ['id' => 1, 'name' => '赵大', 'email' => 'zhaoda@qq.com', 'hello', 'php', 'js'];printf('原数组: <pre>%s</pre> <hr>', print_r($arr, true));printf('取反数组: <pre>%s</pre> <hr>', print_r(array_reverse($arr), true));

<body><fieldset class="list"><legend>尾部追加 头部删除</legend><?php $arr = [1, 2, 3, 4, 5];foreach ($arr as $value) : ?><div class="box"> <?= $value ?></div><?php endforeach ?><?phpecho "<hr>";array_push($arr, $arr[count($arr) - 1] + 1);array_shift($arr);?><?php foreach ($arr as $value) : ?><div class="box"> <?= $value ?></div><?php endforeach ?><?phpecho "<hr>";array_push($arr, $arr[count($arr) - 1] + 1);array_shift($arr);?><?php foreach ($arr as $value) : ?><div class="box"> <?= $value ?></div><?php endforeach ?><?phpecho "<hr>";array_push($arr, $arr[count($arr) - 1] + 1);array_shift($arr);?><?php foreach ($arr as $value) : ?><div class="box"> <?= $value ?></div><?php endforeach ?></fieldset><fieldset class="list"><legend>头部追加 尾部删除</legend><?php $arr = [1, 2, 3, 4, 5];foreach ($arr as $value) : ?><div class="box2"> <?= $value ?></div><?php endforeach ?><?phpecho "<hr>";array_unshift($arr, $arr[0] - 1);array_pop($arr);?><?php foreach ($arr as $value) : ?><div class="box2"> <?= $value ?></div><?php endforeach ?><?phpecho "<hr>";array_unshift($arr, $arr[0] - 1);array_pop($arr);?><?php foreach ($arr as $value) : ?><div class="box2"> <?= $value ?></div><?php endforeach ?><?phpecho "<hr>";array_unshift($arr, $arr[0] - 1);array_pop($arr);?><?php foreach ($arr as $value) : ?><div class="box2"> <?= $value ?></div><?php endforeach ?></fieldset></body>

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号