获取二维数组中的元素(PHP 5.5新增函数),兼容低版本处理
来源:互联网 发布:剑三捏脸数据成女南风 编辑:程序博客网 时间:2024/06/03 12:30
function i_array_column($input, $columnKey, $indexKey=null){
if(!function_exists('array_column')){
$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;
}else{
return array_column($input, $columnKey, $indexKey);
}
}
if(!function_exists('array_column')){
$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;
}else{
return array_column($input, $columnKey, $indexKey);
}
}
阅读全文
0 0
- 获取二维数组中的元素(PHP 5.5新增函数),兼容低版本处理
- 获取二维数组中的元素(PHP 5.5新增函数),兼容低版本处理
- php array_column()函数 php低版本兼容处理
- 让array_column()函数兼容低版本PHP
- 如何做新增结构性标签低版本的兼容
- html5新增标签的低版本 浏览器兼容
- PHP中的数组处理函数
- SVG在低版本ImageView中的兼容
- 指针获取二维数组中的首元素地址
- PHP数组唯一函数array_unique对二维数组的处理
- php中的二维数组
- android sdk 兼容低版本的处理方法
- jQuery 1.9 兼容低版本jQuery插件的处理方法
- PHP中的数组处理函数总结
- PHP中的数组处理函数总结
- 【php】php函数array_shift()在删除数组元素中的用法
- PHP二维数组排序函数
- php二维数组排序函数
- spring 中的 scope 详解
- 面向对象的内存解析
- 关于二级存储的三大误解
- const static 与static const的使用
- 项目: 老王开枪
- 获取二维数组中的元素(PHP 5.5新增函数),兼容低版本处理
- eharts散点图 调整点的颜色和大小。
- spring小结
- Windows 包管理器 Chocolatey
- R文件下所有数据读取与文本字符处理
- where you go?
- 自己写的一个分页效果
- Linux基础
- 一篇文章了解爬虫技术现状