Blogger Information
Blog 20
fans 0
comment 0
visits 8099
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
5种数组函数
P粉191340380
Original
654 people have browsed it

5种数组函数

array_intersect($arr1,$arr2):返回差集结果数组

  1. $arr1 = [1,5,8,9,12,15];
  2. $arr2 = [4,6,8,11,12,16];
  3. $arr = array_intersect($arr1, $arr2);
  4. print_r($arr);
  5. echo '<hr>';

array_merge($arr1,$arr2):合并

  1. $arr1 = ['id'=> '1'];
  2. $arr2 = ['name'=>'老李','sex'=>'男','age'=>17];
  3. $arr = array_merge($arr1,$arr2);
  4. print_r($arr);
  5. echo '<hr>';

natsort($arr):自然排序,忽视键名

  1. $arr = ['string1','string6','string3','string12','string8'];
  2. natsort($arr);
  3. print_r($arr);
  4. echo '<hr>';

array_rand($arr,数值):从数组中随机取出一个或多个元素

  1. $arr = ['name'=>'老李','sex'=>'男','age'=>17,'score'=>12];
  2. print_r(array_rand($arr,2));
  3. echo '<hr>';

shuffle($arr):将数组的顺序打乱

  1. $arr = [1,2,3,4,5,6,7];
  2. print_r(shuffle($arr));
  3. echo '<hr>';
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!