array_combine
Create an array by using one array as key and another as its value
array_combine()
function creates a new array by combining two arrays, one of which is the key name and the other array has the key value.
Note: The number of elements in the key name array and the key value array must be the same!
If one of the arrays is empty, or the number of elements in the two arrays is different, the function returns false.
Create a new array by combining two arrays, one of which is the key name and the other is the key value:
<?php $fname = array ( "Bill" , "Steve" , "Mark" ) ; $age = array ( "60" , "56" , "31" ) ; $c = array_combine ( $fname , $age ) ; print_r ( $c ) ; ?>
Try it yourself
array_combine ( keys , values ) ;
parameter | describe |
---|---|
keys | Required. Keyname array. |
values | Required. Key value array. |