Blogger Information
Blog 11
fans 0
comment 1
visits 15619
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php数组使用1
JasonKim的博客
Original
847 people have browsed it
1、array_values($arr) 将数组转换成索引数组
$arr1 = ['id'=>10,'name'=>'杨过','sex'=>'male','salary'=>8900];
echo '<pre>'.var_export(array_values($arr1),true).'<hr>';

2、array_column($arr,$col,$boll); 获取多维数组的列表组成的数组。
$arr2 = [];
$arr2 = [
    ['id'=>10,'name'=>'杨过','sex'=>'male','salary'=>8900],
    ['id'=>11,'name'=>'欧阳克','sex'=>'male','salary'=>7900],
    ['id'=>12,'name'=>'小龙女','sex'=>'male','salary'=>8900]
    ];
echo '<pre> 查询指定列:'.var_export(array_column($arr2,'salary'),true).'<hr>';
echo '<pre> 查询指定列与值:'.var_export(array_column($arr2,'salary','name'),true).'<hr>';

3、array_keys($arr);返回当前数组的键名组成的新数组
echo '<pre> 返回以键名组成的新数组:'.var_export(array_keys($arr2),true).'<hr>';
// 返回指定的值所对应的键名
echo '<pre> 返回以键名组成的新数组'.var_export(array_keys($arr1,'male'),true).'<hr>';

4、in_array(); 判断值是否存在数组中
echo in_array('male',$arr1) ? '存在' :'不存在','<hr>';

5、array_search($val,$arr) 在数组中查询指定的值并返回键名
$res = array_search('male',$arr1);
echo $res ? :'没有找到';
echo $arr1[$res];

6、array_key_exists($key,$arr); 判断键名是否存在数组中
echo array_key_exists('name',$arr1) ? '键名存在':'键名不存在';

7、array_flip(); 数组键值互换
echo var_export(array_flip($arr1),true);

8、array_reverse(); 数组翻转
echo var_export(array_reverse($arr1),true);


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