Blogger Information
Blog 43
fans 4
comment 0
visits 19258
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP数组常用函数
汇享科技
Original
420 people have browsed it

常用数组函数

51050-zf9r5zoi01m.png

  1. // array_merge合并一个或多个数组返回一个新数组
  2. $arr1 = [1,5,8];
  3. $arr = ['a','b','c'];
  4. $res = array_merge($arr,$arr1);
  5. printf('<pre>%s</pre><hr>',print_r($res,true));
  6. // array_unique去除数组中重复的值
  7. $arr = [1,1,2,5,4];
  8. $res = array_unique($arr);
  9. printf('<pre>%s</pre><hr>',print_r($res,true));
  10. // array_chunk将数组拆分成二维数组
  11. $res = array_chunk($arr,3);
  12. printf('<pre>%s</pre><hr>',print_r($res,true));
  13. // array_flip将数组中的值和键进行交换
  14. $arr = ['id'=>1,'name'=>'小王','age'=>20];
  15. $res = array_flip($arr);
  16. printf('<pre>%s</pre><hr>',print_r($res,true));
  17. // array_combine将两个数组合并成一个数组 一个当键名一个当值
  18. $arr = ['a','b','c'];
  19. $arr1 = [1,2,3];
  20. $res = array_combine($arr,$arr1);
  21. printf('<pre>%s</pre><hr>',print_r($res,true));
  22. // array_rand随机取出键名
  23. $arr = ['id'=>2,'name'=>'小刘','age'=>30,'kecheng'=>'php'];
  24. $a = array_rand($arr,3);
  25. printf('<pre>%s</pre><hr>',print_r($a,true));
  26. print_r($arr[$a[0]].'<br>');
  27. print_r($arr[$a[1]].'<br>');
  28. print_r($arr[$a[2]].'<br>');
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!