开发者

PHP - creating a 2-dimensional array

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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜