加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

自己写的兼容低于PHP 5.5版本的array_column()函数

发布时间:2020-12-12 20:26:27 所属栏目:PHP教程 来源:网络整理
导读:array_column 用于获取二维数组中的元素(PHP 5.5新增函数),但我们有时候需要在低版本的PHP环境中使用… foreach ((array)$input AS $key = $row){ if ($columnKeyIsNumber) { $tmp = array_slice($row,1); $tmp = (is_array($tmp) !empty($tmp)) ? current(

array_column 用于获取二维数组中的元素(PHP 5.5新增函数),但我们有时候需要在低版本的PHP环境中使用…

foreach ((array)$input AS $key => $row) { if ($columnKeyIsNumber) { $tmp = array_slice($row,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;

}
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读