goodname(CSDN新版论坛总版主): 在哪个版本下? PHP Version 4.2.3 Fatal error: Call to undefined function: array_combine() in /home/yjj/public_html/index.php on line 4
php手册的,我这里没有php环境了,看着手册写的。array_combine (PHP 5 CVS only)array_combine -- Creates an array by using one array for keys and another for its values Description array array_combine ( array keys, array values) Returns an array by using the values from the keys array as keys and the values from the values array as the corresponding values. Returns FALSE if the number of elements for each array isn't equal or if the arrays are empty. 例子 1. A simple array_combine() example<?php $a = array('green','red','yellow'); $b = array('avocado','apple','banana'); $c = array_combine($a, $b);print_r($c);/* Outputs: Array ( [green] => avocado [red] => apple [yellow] => banana ) */ ?>
$arr1 = array("a"=>0,"b"=>0,"c"=>0,"d"=>0);
$arr2 = array(1,2,3,4);
foreach($arr1 as $k=>$v) {
list(,$arr1[$k]) = each($arr2);
}
print_r($arr1);
?>
list($id, $name, $salary) = mysql_fetch_row($result);
list函数
while(list($k,$v)=each($arr1)){
$arr1[$k] = $arr2[$i]);
$i++;
}
在哪个版本下?
PHP Version 4.2.3
Fatal error: Call to undefined function: array_combine() in /home/yjj/public_html/index.php on line 4
(PHP 5 CVS only)array_combine -- Creates an array by using one array for keys and another for its values
Description
array array_combine ( array keys, array values)
Returns an array by using the values from the keys array as keys and the values from the values array as the corresponding values. Returns FALSE if the number of elements for each array isn't equal or if the arrays are empty. 例子 1. A simple array_combine() example<?php
$a = array('green','red','yellow');
$b = array('avocado','apple','banana');
$c = array_combine($a, $b);print_r($c);/* Outputs:
Array
(
[green] => avocado
[red] => apple
[yellow] => banana
)
*/
?>
$array1=array("a"=>0,"b"=>0,"c"=>0,"d"=>0);
$array2=array(3,8,2,9);
$array3=array_unique(array_merge($array1,$array2));
sort($array3);
print_r($array3);
?>
<?
$arr1 = array("a"=>0,"b"=>0,"c"=>0,"d"=>0);
$arr2 = array(1,2,3,4);
$i = 0;
while(list($key,$val) = each($arr1)){
$arr1[$key] = $arr2[$i];
$i++;
}
print_r($arr1);
?>