zoukankan      html  css  js  c++  java
  • php 5.5使用 array_column的方法

    <pre>
    php 5.5使用 array_column的方法
    </pre>

    <pre>
    public 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;
    }
    </pre>

  • 相关阅读:
    BZOJ1029_建筑抢修_KEY
    黑匣子_KEY
    食物链_KEY
    滑雪_KEY
    抓猫_KEY
    线段树初步__ZERO__.
    听说alphago又要挑战sc2了?——我眼中的人工智能
    我眼中的算法
    opencv拼接相关1
    Cstring到string
  • 原文地址:https://www.cnblogs.com/newmiracle/p/11856207.html
Copyright © 2011-2022 走看看