批改状态:合格
老师批语:

// array_merge合并一个或多个数组返回一个新数组$arr1 = [1,5,8];$arr = ['a','b','c'];$res = array_merge($arr,$arr1);printf('<pre>%s</pre><hr>',print_r($res,true));// array_unique去除数组中重复的值$arr = [1,1,2,5,4];$res = array_unique($arr);printf('<pre>%s</pre><hr>',print_r($res,true));// array_chunk将数组拆分成二维数组$res = array_chunk($arr,3);printf('<pre>%s</pre><hr>',print_r($res,true));// array_flip将数组中的值和键进行交换$arr = ['id'=>1,'name'=>'小王','age'=>20];$res = array_flip($arr);printf('<pre>%s</pre><hr>',print_r($res,true));// array_combine将两个数组合并成一个数组 一个当键名一个当值$arr = ['a','b','c'];$arr1 = [1,2,3];$res = array_combine($arr,$arr1);printf('<pre>%s</pre><hr>',print_r($res,true));// array_rand随机取出键名$arr = ['id'=>2,'name'=>'小刘','age'=>30,'kecheng'=>'php'];$a = array_rand($arr,3);printf('<pre>%s</pre><hr>',print_r($a,true));print_r($arr[$a[0]].'<br>');print_r($arr[$a[1]].'<br>');print_r($arr[$a[2]].'<br>');
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号