Reputation: 1
$city=array('delhi','noida','mumbai','noida');
$name=array('ankit','atul','ramu','manu');
I want to create a 2-dimensional array using the two arrays above, with the name of the cities as keys and the corresponding names as the values. The names must be sorted.
Upvotes: 0
Views: 139
Reputation: 2876
There is a function called array_combine($array1, $array2) which make your 2 arrays combine as Key(as array1) and Value(as array2).
$Mixedarray = array_combine($array1, $array2);
Upvotes: 0
Reputation: 655269
Try this:
$arr = array_combine($city, $name);
asort($arr);
array_combine
creates an array using the array values of the first argument as key and the values of the second array as values. And asort
sorts the array values while maintaining the association of key and value.
Upvotes: 4