Hi all

I know how to sort an array but I dont know how to sort an array according to a value in the second array...


    $array1 = array(
                array('name'=>'01','number' => 1),
                array('name'=>'07','number' => 7),
                array('name'=>'05','number' => 5),
                array('name'=>'06','number' => 6),
                array('name'=>'02','number' => 2),
                array('name'=>'03','number' => 3),
                array('name'=>'11','number' => 11),
                array('name'=>'08','number' => 8),
                array('name'=>'09','number' => 9),
                array('name'=>'10','number' => 10),
                array('name'=>'04','number' => 4),
                array('name'=>'12','number' => 12)              

this is the array 1...

i want to rearrange the arrays that are inside this $array1 according to the number in the second array...

Recommended Answers

All 3 Replies

Correct me if I'm wrong, but if this array is created by a loop returned from a query, then you can use ORDER BY to put them in the right order in the first place.

foreach ($array1 as $array2) 
array_multisort($number, $array1);

pritaeas thanks for your suggestion but I am getting values one at a time so cannot sort it through SQL...

pzuurveen... excellent solution works for me Thanks!

Thanks pplz

Your help is much appriciated

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.