Array_column () functions earlier than PHP5.5

Source: Internet
Author: User
This article mainly introduces array_column () functions that are compatible with PHP5.5 and earlier versions. array_column is a new function in PHP5.5 and may be used in earlier versions, for more information, see array_column to obtain elements in a two-dimensional array (PHP 5.5 new function...

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;  }}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.