0

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

<?php

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

3
Contributors
3
Replies
27
Views
3 Years
Discussion Span
Last Post by t_thakar
0

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.

3
foreach ($array1 as $array2) 
    {
    $number[]=$array2['number'];
    }
array_multisort($number, $array1);
0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.