2

I have one multidimensional array and another array.I need to sort multidimensional array by another array value.

Array([0] => 7[1] => 6 [2] => 5[3] => 4)

Using the above array value need to sort the below array by this value [Outlets][id].both array need to use only values of array. multiarray should sort like this ie,..([Outlets][id] => 7,[Outlets][id] => 6,[Outlets][id] => 5,[Outlets][id] => 4)

  Array
  ( [0] => Array
    (
        [Outlets] => Array
            (   [id] => 4
                [name] => Chef Bakers, Bellandur
                [image] => chefbakers.jpg
                [partner_categories_id] => 5
            )

        [Localities] => Array
            ([name] => Bellandur Gate (Nr Total Mall))
    )
[1] => Array
    (
        [Outlets] => Array
            (   [id] => 7
                [name] => Homechefs - Rajasthani breakfast, Sarjapur
                [image] => 1413881493hoechefs.jpg
                [partner_categories_id] => 4
            )
       [Localities] => Array
            ([name] => Iblur Jn (Near Suncity))
    )
[3] => Array
    ( [Outlets] => Array
            (   [id] => 6
                [name] => Meat Mart, Sarjapur
                [image] => 1414651527meatmart.jpg
                [partner_categories_id] => 3
            )
        [Localities] => Array([name] => Bellandur Gate (Nr Total Mall))
    )
[4] => Array
    (    [Outlets] => Array
            (  [id] => 5
                [name] => Veggiez, Sarjapur
                [image] => 1413881741veg.jpg
                [partner_categories_id] => 6
            )
        [Localities] => Array([name] => Iblur Jn (Near Suncity))
      )
)

please can you help? I haven't seen same ans here. ps:sorry for my bad english

I have fixed:

       $s=$sortvalue_array;
       $res=$Multidimentional_array;
       $new=array();
        foreach($res as $r)
         {
         $a=array_search($r['Outlets']['id'],$s);
          $new[$a]=$r;
         }
       ksort($new);
       print_r($new); 
manimaran
  • 21
  • 3

0 Answers0