php5.5新函数array_column
2014-12-28 09:56
621 查看
php5.5新增了一个新的数组函数,感觉挺使用的,低版本的实现按照如下实现
if(!function_exists('array_column')){ function array_column($input, $columnKey, $indexKey=null){ $columnKeyIsNumber = (is_numeric($columnKey)) ? true : false; $indexKeyIsNull = (is_null($indexKey)) ? true : false; $indexKeyIsNumber = (is_numeric($indexKey)) ? true : false; $result = array(); foreach((array)$input as $key=>$row){ if($columnKeyIsNumber){ $tmp = array_slice($row, $columnKey, 1); $tmp = (is_array($tmp) && !empty($tmp)) ? current($tmp) : null; }else{ $tmp = isset($row[$columnKey]) ? $row[$columnKey] : null; } if(!$indexKeyIsNull){ if($indexKeyIsNumber){ $key = array_slice($row, $indexKey, 1); $key = (is_array($key) && !empty($key)) ? current($key) : null; $key = is_null($key) ? 0 : $key; }else{ $key = isset($row[$indexKey]) ? $row[$indexKey] : 0; } } $result[$key] = $tmp; } return $result; } }
相关文章推荐
- 自己写的兼容低于PHP 5.5版本的array_column()函数
- php5.5新数组函数array_column使用
- php5.5新数组函数array_column应用实例分享
- 自己写的兼容低于PHP 5.5版本的array_column()函数
- array_column php 函数 自定义版本 php_version<5.5
- php5.5新数组函数array_column使用
- PHP5.5的新方法array_column
- PHP5.5中新增foreach() 循环支持标量迭代键-foreach+list和array_column用法
- array_column php 函数
- 让array_column()函数兼容低版本PHP
- PHP常用数组函数系列--array_column
- 让array_column()函数兼容低版本PHP
- php数组函数分析--array_column
- 实现PHP5.5版本的array_column,并扩展取多列的功能
- php in_array 函数使用说明与in_array需要注意的地方说明
- php自定义函数call_user_func和call_user_func_array详解
- PHP数组的交集array_intersect(),array_intersect_assoc(),array_inter_key()函数的小问题
- PHP stdClass Object转array 函数
- php自定义函数call_user_func和call_user_func_array详解
- PHP in_array() 函数