tags:

views:

39

answers:

2

$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.

plz help me

+4  A: 

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.

Gumbo
Dammit Gumbo, you're just too fast for me! +1
Peter Bailey
A: 

Hi,

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);

VAC-Prabhu