arrays - array_multisort not working PHP -
please need help. want sort array ascending order priority time.
heres array
array ( [process] => array ( [0] => array ( [name] => p1 [burst_time] => 2 [priority_time] => 3 ) [1] => array ( [name] => p2 [burst_time] => 2 [priority_time] => 4 ) [2] => array ( [name] => p3 [burst_time] => 2 [priority_time] => 1 ) ) )
i tried code doesn't work me. thank in advanced :)
foreach ($data $key => $row) { $mid[$key] = $row; } array_multisort($mid, sort_asc, $data);
you're using array_multisort
don't need sort in multiple dimensions. simple usort
enough:
$data = array( "process" => array( array( "name" => p1, "burst_time" => 2, "priority_time" => 3 ), array( "name" => p2, "burst_time" => 2, "priority_time" => 4 ), array( "name" => p3, "burst_time" => 2, "priority_time" => 1 ) ) ); usort($data["process"], "sort_by_priority_time"); function sort_by_priority_time($a, $b) { return $a["priority_time"] - $b["priority_time"]; }
Comments
Post a Comment