你可以使用
array_map:
$arrKeys = array('str', 'str', 'otherStr');
$arrVals = array('1.22', '1.99', '5.17');
function foo($key, $val) {
return array($key=>$val);
}
$arrResult = array_map('foo', $arrKeys, $arrVals);
print_r($arrResult);
Array
(
[0] => Array
(
[str] => 1.22
)
[1] => Array
(
[str] => 1.99
)
[2] => Array
(
[otherStr] => 5.17
)
)
顺便说一句,如果你升级到PHP 5.3,你可以使用匿名函数来做到这一点,它更优雅:
array_map(function($key, $val) {return array($key=>$val);}, $arrKeys, $arrVals);