Blogger Information
Blog 47
fans 0
comment 0
visits 21299
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP数组函数
P粉036614676
Original
366 people have browsed it

1.函数大纲

2.重点函数讲解

  1. <?php
  2. $arr1 = array(
  3. array(1,2,3),
  4. array(2,3,1),
  5. array(3,1,2)
  6. );
  7. function compare($x,$y)
  8. {
  9. if($x[0]<$y[0])
  10. {
  11. return 1;
  12. }else if($x[0]==$y[0])
  13. {
  14. return 0;
  15. }
  16. else
  17. {
  18. return -1;
  19. }
  20. }
  21. usort($arr1,'compare');//改变数组排序的顺序
  22. foreach ($arr1[0] as $x)
  23. {
  24. echo $x .PHP_EOL;
  25. }
  1. <?php
  2. $arr1 = array(
  3. array("csd"=>1,"asdf"=>2,"asdfg"=>3),
  4. array("asd"=>1,"asdf"=>2,"asdfg"=>3),
  5. array("dsd"=>1,"asdf"=>2,"asdfg"=>3)
  6. );
  7. array_multisort($arr1,SORT_DESC);
  8. //SORT_ASC:升序
  9. //SORT_DESC相反
  10. foreach ($arr1[0] as $a=>$y)
  11. {
  12. echo $a . $y;
  13. }
  1. <?php
  2. $arr = [1,1,2,3,1,2,3];
  3. $x1 = count($arr);
  4. $arr2 = sizeof($arr);
  5. //以上两个函数功能相同,都是计算数组中元素的个数,如果是空数组,则返回0
  6. $arr3 = array_count_values($arr);
  7. echo $arr3[2];//[x],$arr[x],就是x在数组中出现的次数
  1. <?php
  2. /**
  3. * 回调:
  4. * array_filter() :只返回数组中为true的元素组成的数组
  5. * is_scalar() :是否是标量
  6. * array_map()
  7. * array_reduce()
  8. *
  9. */
  10. //1.数组排序
  11. $arr = [
  12. [1,3,5],
  13. [2,4,6],
  14. [5,2,3]
  15. ];
  16. array_map(function ($item)
  17. {
  18. $item[0]++;
  19. },$arr);
  20. print_r($arr);
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