自己写的兼容低于PHP 5.5版本的array_column()函数
2014-10-24 00:00
597 查看
array_column 用于获取二维数组中的元素(PHP 5.5新增函数),但我们有时候需要在低版本的PHP环境中使用…
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()函数
- 让array_column()函数兼容低版本PHP
- array_column php 函数 自定义版本 php_version<5.5
- 让array_column()函数兼容低版本PHP
- 获取二维数组中的元素(PHP 5.5新增函数),兼容低版本处理
- 高版本兼容低版本array_column自己实现
- php5.5新数组函数array_column使用
- php array_column()函数 php低版本兼容处理
- php5.5新数组函数array_column应用实例分享
- php5.5新数组函数array_column使用
- array_column()函数兼容低版本
- 实现PHP5.5版本的array_column,并扩展取多列的功能
- 获取二维数组中的元素(PHP 5.5新增函数),兼容低版本处理
- php5.5新函数array_column
- PHP5.5的新方法array_column
- PHP常用数组函数系列--array_column
- php5.2 、5.3、5.4、5.5、5.6 各个版本升级不兼容点
- php 自己写的一个数组分类合并array_merge(函数的剖析)
- ecmall 兼容 php5.5以上版本
- array_column php 函数