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.
array_multisort()as well, except your second code sample is clearly JS and not PHP.