Home >Backend Development >PHP Tutorial >The array_column() function I wrote myself that is compatible with versions lower than PHP 5.5, 5.5array_column_PHP tutorial

The array_column() function I wrote myself that is compatible with versions lower than PHP 5.5, 5.5array_column_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:16:031071browse

The array_column() function written by myself is compatible with versions lower than PHP 5.5, 5.5array_column

array_column is used to obtain elements in a two-dimensional array (new function in PHP 5.5), but we sometimes need to use it in a lower version of PHP environment...

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

What is the latest version of apache currently? Compatible with php536 and mysql 55117

The following are the installation steps I found online. I have never configured it under apache.
If you don’t want to bother, you can download a ready-made component, such as PHPnow, which integrates apache+php+mysql+Zend Optimizer+eAccelerator Everything that needs to be configured is integrated, just install it
Of course it is 2003

How can the cms system be compatible with various versions of php (40 or 50) servers?

To be able to run on both php4 and php5, you need to have a version judgment function

You can do this:
if (version_compare( phpversion(), ' 5', '<' ) )
include_once( 'php4.php' ) ;//php4 related configuration files or calling functions
else
include_once( 'php5.php' ) ;//php5 Related files or calling functions
}
In this way, in different environments, you can call different files to realize your functions, but the specific implementation is much more complicated.
Hope it helps you

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/899062.htmlTechArticleWritten by myself, the array_column() function is compatible with versions lower than PHP 5.5. 5.5array_column array_column is used to obtain a two-dimensional array. Elements in (new function in PHP 5.5), but sometimes we need to lower...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn