更改json数组顺序

Iam developing an appliacation using CI.I have got a problem and I need a help for that.this is my problem. I have an array generated with php:

Array
(
[0] => Array
    (
        [0] => 3
        [1] => 0
    )

[1] => Array
    (
        [0] => 2
        [1] => 0
    )

[2] => Array
    (
        [0] => 1
        [1] => 246
    )

[3] => Array
    (
        [0] => 0
        [1] => 4528
    )

)

This is the code that genarate above array.

public function get_previous_months_total()
{
    $f = 1;
    $dataset2 = array();
    $result;
    for($i=0;$i<4;$i++){    

            $firstday = mktime(0, 0, 0, date('m')-$f, 1, date('Y'));
            $lastday = mktime(0, 0, 0, date('m')-$i, 0, date('Y'));

            $end = date("Y-m-d", $lastday);
            $start = date("Y-m-d", $firstday);
            $f++;               
            $result = $this->LineChart_Model->get_months_total($start,$end);
            foreach ($result as $return_result ){
                    $dataset2[] =        array($i,int)$return_result['SUM(operation_production)']);

            }

    }   

    $mon = array(array_reverse($dataset2));
    return $mon;
}

Here is the code in the Model.

public function get_months_total($start,$end){

    $sql = "SELECT SUM(operation_production) FROM plant WHERE date BETWEEN '".$start."' AND        '".$end."' ORDER BY operation_id DESC";
    $result = $this->linechart_db->query($sql);
    return $result->result_array();
}

after this I encode this using json_encode which gives me the result below:

var total = [
    [
        3,
        0
    ],
    [
        2,
        0
    ],
    [
        1,
        246
    ],
    [
        0,
        4528
    ]
];

I need to change the order to this:

var total = [
    [
        0,
        0
    ],
    [
        1,
        0
    ],
    [
        2,
        246
    ],
    [
        3,
        4528
    ]
];

please help me on this. I have tried many ways, but none have worked. any help is really appreciated.

You should be able to use the array_mulisort() function to resolve this issue.

**EDIT:

After further investigation the array_multisort() function will not give you your answer, I apologize.

Since the values of your array are already set, your going to have to manipulate them to get the result you want. Here is what worked for me (in your code just replace the $oldArray variable with the name of your array) :

$replacementArray = array();
$i                = 0;

foreach($oldArray as $array) {
    $newArray =[$i, $array[1]];

    array_push($replacementArray, $newArray);

    $i++;
}

$finalArray = array_replace($oldArray, $replacementArray);
$json       = json_encode($finalArray);

echo $json;

This will give the following output:

[[0,0],[1,0],[2,246],[3,4528]]