Blogger Information
Blog 34
fans 0
comment 0
visits 20126
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP数组函数
OC的PHP大牛之路
Original
417 people have browsed it

PHP数组函数

队列

  1. // 队列
  2. // 1.尾部追加(array_push()),头部删除(array_shift())
  3. $arr = [];
  4. echo array_push($arr,5,6,7);
  5. echo array_push($arr,8);
  6. echo array_push($arr,9);
  7. print_r($arr);
  8. echo array_shift($arr);
  9. echo array_shift($arr);
  10. // 2.头部追加(array_unshift()),尾部删除(array_pop())
  11. $arr = [];
  12. echo array_unshift($arr,5,6,7);
  13. echo array_unshift($arr,8);
  14. echo array_unshift($arr,9);
  15. print_r($arr);
  16. echo array_pop($arr);
  17. echo array_pop($arr);

常用数组函数

  1. // 1.array_intersect 计算数组的交集
  2. $arr1 = [1,2,3];
  3. $arr2 = [3,4,5];
  4. print_r(array_intersect($arr1,$arr2));
  5. // 2.array_key_exists 检查数组里是否有指定的键名或索引
  6. $arr = ['a' => 1, 'b' => 2];
  7. var_dump(array_key_exists('a',$arr));
  8. // 3.array_column 返回数组中指定的一列
  9. $arr = [
  10. ['a'=>'a1','b'=>'b1'],
  11. ['a'=>'a2','b'=>'b2'],
  12. ['a'=>'a3','b'=>'b3'],
  13. ];
  14. print_r(array_column($arr,'b')) ;
  15. // 4.array_merge 合并一个或多个数组
  16. $arr1 = [1,2,3];
  17. $arr2 = [4,5,6];
  18. print_r(array_merge($arr1,$arr2));
  19. // 5.array_change_key_case 将数组中的所有键名修改为全大写或小写
  20. $arr = ["abc" =>1 , "xyz" => 2];
  21. print_r(array_change_key_case($arr, CASE_UPPER));
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