Why array_multisort doesn't sort in my case ?
The case is simple i followed many of examples manuals and i have no idea why it doesnt work. Teoretical it should work 100%. Maybe i have spend to many time trying to fix it over and over again and i cant see samething obvious now.
Here is the case:
I want to sort my array $this->array
over defined sort dirrection for columns in other array $order
simple sorting function:
$preSort = [];
foreach ($order as $column => $direction) {
$valueArray = [];
foreach ($this->array as $key => $row) {
$valueArray[] = $row[$column];
}
$preSort[] = $valueArray;
$preSort[] = $this->getSortDirection($direction) | $this->getSortType(key($valueArray), $column);
}
$preSort[] = $this->array;
call_user_func_array('array_multisort', $preSort);
And here it is how data looks like:
$order
array ('id' => 'asc', 'name' => 'desc',)
$this->array
array ( 0 => array ( 'id' => 1, 'name' => 'samsonasik', 'description' => 'aaaaaaa', ), 1 => array ( 'id' => 2, 'name' => 'abdul malik ikhsan', 'description' => 'bbbbbb', ), 2 => array ( 'id' => 3, 'name' => 'superman', 'description' => 'cccccccc', ), )
here you have extra functions used by me:
protected function getSortDirection($string)
{
return mb_strtolower($string) == 'asc' ? SORT_ASC : SORT_DESC;
}
protected function getSortType($key, $column)
{
return is_numeric($this->array[$key][$column]) ? SORT_NUMERIC : SORT_STRING;
}