如何通过randNum对多维数组进行排序

Hi i've created an array with 4 rows and 5 columns. I now want to sort the array by the random number in my array but not how to sort multidimensional arrays. I seen online that I may have use a for each loop but not sure where to place it if I were to use one. Also I'm not sure how I to tell the sortarray what column I want to sort as I don't have any id for the outputs. Any help would be myuch appreciated.

<?php 
$vyear = 1;
$vmonth= 3;
$date = "2015-11-25";
$t = 0;

echo date("M-y") . "<br>";

$startdate = "2009/06/01";

$start = strtotime($date);

$currentdate = $start;

$newdate = strtotime (  $t .'month' , strtotime ( $date ) ) ;
$ndate = date ( 'm-Y-d' , $newdate );

echo $ndate;



 echo "<br>";
 echo "<br>";
 echo $date;

$times_table = array();
        for($i = 0; $i <= 3; $i++){
            $times_table[$i] = array();

        }
echo "<pre>";

       for($i = 0; $i <= 3; $i++){
             for($j = 0; $j <= 4; $j++){

               if ($j == 0){
                $times_table[$i][$j]=  "Version 4" ;
            }
                else if ($j == 1){
                $cur_date = date("M-y", $currentdate);

                $currentdate = strtotime('+1 month', $currentdate);

                $times_table[$i][$j]= $cur_date ;

          echo  $cur_date . ">". "<br />";
                }
                else{
                    $times_table[$i][$j]=  "gary" ;
                }
                if ($j == 3) {
                    $numbers = mt_rand(1, 100);
                    $times_table[$i][$j]= $numbers ;

                }
                if ($j == 4){

                    if($i == 0 || $i == 3)
                    {
                        $pay = "P";

                    $times_table[$i][$j]= $pay ;
                    }
                    else{
                        $int = "I";

                    $times_table[$i][$j]= $int ;

                    }
                }

            }

            }




// echo $times_table[1][3] ;
print_r($times_table);
 echo "</pre>";
    ?>

I added PHP's usort function

function sortByRandomNo($a, $b) {
    return $a[3] - $b[3];
}

usort($times_table, 'sortByRandomNo');

usort - Sorts an array by values using a user-defined comparison function

Here, your random number is in index 3 and we are comparing numbers in that index

So your code is:

<?php 
$vyear = 1;
$vmonth= 3;
$date = "2015-11-25";
$t = 0;

echo date("M-y") . "<br>";

$startdate = "2009/06/01";

$start = strtotime($date);

$currentdate = $start;

$newdate = strtotime (  $t .'month' , strtotime ( $date ) ) ;
$ndate = date ( 'm-Y-d' , $newdate );

echo $ndate;



 echo "<br>";
 echo "<br>";
 echo $date;

$times_table = array();
        for($i = 0; $i <= 3; $i++){
            $times_table[$i] = array();

        }
echo "<pre>";

       for($i = 0; $i <= 3; $i++){
             for($j = 0; $j <= 4; $j++){

               if ($j == 0){
                $times_table[$i][$j]=  "Version 4" ;
            }
                else if ($j == 1){
                $cur_date = date("M-y", $currentdate);

                $currentdate = strtotime('+1 month', $currentdate);

                $times_table[$i][$j]= $cur_date ;

          echo  $cur_date . ">". "<br />";
                }
                else{
                    $times_table[$i][$j]=  "gary" ;
                }
                if ($j == 3) {
                    $numbers = mt_rand(1, 100);
                    $times_table[$i][$j]= $numbers ;

                }
                if ($j == 4){

                    if($i == 0 || $i == 3)
                    {
                        $pay = "P";

                    $times_table[$i][$j]= $pay ;
                    }
                    else{
                        $int = "I";

                    $times_table[$i][$j]= $int ;

                    }
                }

            }

            }


// echo $times_table[1][3] ;
print_r($times_table);
 echo "</pre>";

function sortByRandomNo($a, $b) {
    return $a[3] - $b[3];
}

usort($times_table, 'sortByRandomNo');

echo "<pre>";
print_r($times_table);
echo "</pre>";

and your output:

Dec-15
11-2015-25

2015-11-25
Nov-15>
Dec-15>
Jan-16>
Feb-16>
Array
(
    [0] => Array
        (
            [0] => Version 4
            [1] => Nov-15
            [2] => gary
            [3] => 2
            [4] => P
        )

    [1] => Array
        (
            [0] => Version 4
            [1] => Dec-15
            [2] => gary
            [3] => 9
            [4] => I
        )

    [2] => Array
        (
            [0] => Version 4
            [1] => Jan-16
            [2] => gary
            [3] => 43
            [4] => I
        )

    [3] => Array
        (
            [0] => Version 4
            [1] => Feb-16
            [2] => gary
            [3] => 45
            [4] => P
        )

)
Array
(
    [0] => Array
        (
            [0] => Version 4
            [1] => Nov-15
            [2] => gary
            [3] => 2
            [4] => P
        )

    [1] => Array
        (
            [0] => Version 4
            [1] => Dec-15
            [2] => gary
            [3] => 9
            [4] => I
        )

    [2] => Array
        (
            [0] => Version 4
            [1] => Jan-16
            [2] => gary
            [3] => 43
            [4] => I
        )

    [3] => Array
        (
            [0] => Version 4
            [1] => Feb-16
            [2] => gary
            [3] => 45
            [4] => P
        )

)