array_column 用于获取二维数组中的元素(php 5.5新增函数),但我们有时候需要在低版本的php环境中使用…
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;
}
}
下面是个在网上找的安装步骤,具体我也没再apache下配置过,
如果不想麻烦可以下个现成的组件,比如PHPnow,集成了apache+php+mysql+Zend Optimizer+eAccelerator需要配置的都集成好了,安装一下就成啦
当然是2003下好啦
要做到既可以在php4上运行,又可以在php5上运行,你需要有一个版本判断的功能
你可以这样:
if (version_compare( phpversion(), '5', ' include_once( 'php4.php' ) ;//php4的相关配置文件或调用函数
else
include_once( 'php5.php' ) ;//php5的相关文件或调用函数
}
这样在不同的环境下,就可以调用不同的文件,实现你的功能,不过具体要实现要复杂的多。
希望对你有帮助
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号