array_combine合并两个数组成为一个新的数组,一个数组用于键,一个数组作为值
/**
* Creates an array by using one array for keys and another for its values
* @link https://php.net/manual/en/function.array-combine.php
* @param array $keys <p>
* Array of keys to be used. Illegal values for key will be
* converted to string.
* </p>
* @param array $values <p>
* Array of values to be used
* </p>
* @return array|false the combined array, false if the number of elements
* for each array isn't equal or if the arrays are empty.
* @meta
*/
function array_combine(array $keys, array $values) { }
示例:
$keys = [
'a', 'b', 'c', 'd', 'e'
];
$values = [
1, 2, 3, 4, 5
];
$result = array_combine($keys, $values);
var_dump($result);
//结果
//array(5) {
// 'a' =>
// int(1)
// 'b' =>
// int(2)
// 'c' =>
// int(3)
// 'd' =>
// int(4)
// 'e' =>
// int(5)
//}