array(
0 => array('id'=> 2, 'title' => 'text', 'category' => 0),
1 => array('id'=> 4, 'title' => 'text', 'category' => 1),
2 => array('id'=> 5, 'title' => 'text', 'category' => 0),
);
array(
0 => array('id'=> 2, 'title' => 'text', 'category' => 0),
2 => array('id'=> 5, 'title' => 'text', 'category' => 0),
1 => array('id'=> 4, 'title' => 'text', 'category' => 1)
);
$array = array(
0 => array('id'=> 2, 'title' => 'text', 'category' => 0),
1 => array('id'=> 4, 'title' => 'text', 'category' => 1),
2 => array('id'=> 5, 'title' => 'text', 'category' => 0),
);
function catSort($a, $b)
{
if ($a['category'] == $b['category']) {
return 0;
}
return ($a['category'] < $b['category']) ? -1 : 1;
}
usort($array, "catSort");
print_r($array);
Array
(
[0] => Array
(
[id] => 2
[title] => text
[category] => 0
)
[1] => Array
(
[id] => 5
[title] => text
[category] => 0
)
[2] => Array
(
[id] => 4
[title] => text
[category] => 1
)
)
$array = array(
0 => array('id'=> 2, 'title' => 'text', 'category' => 0),
1 => array('id'=> 4, 'title' => 'text', 'category' => 1),
2 => array('id'=> 5, 'title' => 'text', 'category' => 0),
);
$category_sort_array = array();
foreach ($array as $key => $row)
$category_sort_array[$key] = $row['category'];
array_multisort($category_sort_array, SORT_ASC, $array);