abstract://range() $arr = range(20,50,3); $arr = range('a','z',3); echo var_export($arr,true),'<br>'; //array_unique() $arr = [45,6,5,45,44,78,7
//range() $arr = range(20,50,3); $arr = range('a','z',3); echo var_export($arr,true),'<br>'; //array_unique() $arr = [45,6,5,45,44,78,78,5,89]; echo var_export(array_unique($arr),true),'<br>'; //array_fill():创建一个有5个元素的数组,并用0进行初始化 $arr = array_fill(0,5,0); echo var_export($arr,true),'<hr>'; //array_rand():从数组中随机取出一些数据,返回的是随机数的键名组成的数组,并非元素值 $arr = [45,6,5,45,44,78,78,5,89]; $keys = array_rand($arr,4);//由$arr数组中键名组成的新数组 //保留键名的键值对 foreach ($keys as $k){ $res[$k] = $arr[$k]; } echo var_export($res,true),'<br>'; //shuffle():将数组的元素随机打乱显示,直接更新原来的数组 shuffle($arr); echo var_export($arr,true),'<br>'; //array_merge() $db_sys = ['host'=>'127.0.0.1','user'=>'root','pwd'=>'root']; $db_user = ['host'=>'localhost','pwd'=>'123456']; $res = array_merge($db_sys,$db_user); echo var_export($res,true),'<br>'; $arr = [10,25,5,14,57,21,6,3]; sort($arr); echo var_export($arr,true),'<br>'; rsort($arr); echo var_export($arr,true),'<br>'; //回调 usort($arr,function ($var1,$var2){ $res = $var1 - $var2; switch ($res){ //降序 // case ($res < 0): // return 1;break; // case ($res > 0): // return -1;break; // case ($res = 0): // return 0;break; //升序 case ($res < 0): return -1;break; case ($res > 0): return 1;break; case ($res = 0): return 0;break; } }); echo var_export($arr,true),'<br>'; $stu = [ ['name'=>'张宏','grade'=>60], ['name'=>'王晓','grade'=>80], ['name'=>'田驰','grade'=>20], ]; echo var_export($stu,true),'<br>'; //usort()适合二维数组排序 usort($stu,function ($m,$n){ //strcmp()比较两个字符串(区分大小写) return strcmp($m['grade'],$n['grade']); }); echo var_export($stu,true),'<br>';
Correcting teacher:韦小宝Correction time:2018-11-19 18:02:17
Teacher's summary:嗯!很不错!下次整理一下可以当做笔记来看了!继续加油吧!!!