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

4
  • That would be an associative array, not a 2 dimensional array. I suggest you show some attempt to actually solve this yourself (or go to rent-a-coder or elancer for help). Commented May 10, 2010 at 14:29
  • 1
    @David I thought this was a Q&A site - is posting a question here not a valid attempt to get help? I thought that was the point. Commented May 10, 2010 at 14:35
  • There is "getting help" and there is "plz send teh codez" Commented May 10, 2010 at 14:49
  • The difference usually lies in the individual's experience level. I don't see anything wrong with this question for a budding developer. Commented May 10, 2010 at 15:01

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Dammit Gumbo, you're just too fast for me! +1
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.