This code is very helpful for beginner in PHP. To break multi-dimension Array into one single array and then you sort it according to your need, In my scenario, I wanted to Sort it with price High to Low and Low to High so I use array_multisort().

and you can use its sorting type flags, for more details look below at code and sample code link.

$list_box_contents = array(
            array(

             array(
                    "price" => 4.99,
                    "params" => NULL,
                    "text" => "demotext","prices" => 4.99,
                ),

             array(
                    "price" => 4.79,
                    "params" => NULL,
                    "text" => "demotext","prices" => 4.79,
                ),

             array(
                    "price" => 5.10,
                    "params" => NULL,
                    "text" => "demotext","prices" => 5.10,
                ),

             array(
                    "price" => 4.20,
                    "params" => NULL,
                    "text" => "demotext","prices" => 4.20,
                ),

        ),
     array(

             array(
                    "price" => 4.08,
                    "params" => NULL,
                    "text" => "demotext","prices" => 4.08,
                ),

             array(
                    "price" => 4.00,
                    "params" => NULL,
                    "text" => "demotext","prices" => 4.00,
                ),

             array(
                    "price" => 3.20,
                    "params" => NULL,
                    "text" => "demotext",
					"prices" => 3.20,
                ),

             array(
                    "price" => 3.19,
                    "params" => NULL,
                    "text" => "demotext",
					"prices" => 3.19,
                ),

        ),

     array(

             array(
                    "price" => 2.86,
                    "params" => NULL,
                    "text" => "demotext",
					"prices" => 2.86,
                ),

             array(
                    "price" => 3.58,
                    "params" => NULL,
                    "text" => "demotext",
					"prices" => 3.58,
                ),

             array(
                    "price" => 2.92,
                    "params" => NULL,
                    "text" => "demotext",
					"prices" => 2.92,
                ),

             array(
                    "price" => 2.90,
                    "params" => NULL,
                    "text" => "demotext",
					"prices" => 2.90,
                ),

        ),

);

$array = $list_box_contents;
// merging multi-dimension array into one array.
$result = array_merge_recursive($array[0],$array[1],$array[2]);
// now Sort array according to price HIGH to Low
array_multisort($result, SORT_DESC);

print_r($array);
foreach ($result as $key => $val) {
   foreach ($val as $new) {
    }
   echo  $new;
  }

For Output and Sample Code Check Links Below:-

Get raw code – http://phpfiddle.org/api/raw/ed7-rxd

Get execution results – http://phpfiddle.org/api/run/ed7-rxd

Demo Code : http://phpfiddle.org/lite/code/ed7-rxd

Advertisements