<?php $array = [ 'note' => [], 'year' => ['2011','2010', '2012'], 'type' => ['conference', 'journal', 'conference'], ]; function array_multisort_custom(array &$array, $columnKey, array $order) { // guard clause/condition if (!array_key_exists($columnKey, $array)) { throw new Exception('Nominated sorting column not found'); } // pad rows to consistent size $maxCount = max(array_map('count', $array)); array_walk($array, fn(&$row) => $row = array_pad($row, $maxCount, null)); // populate first sorting parameter with custom order array $priority = array_flip($order); $default = count($order); foreach ($array[$columnKey] as $v) { $params[0][] = $priority[$v] ?? $default; } // assign reference variables to parameter array for all rows foreach ($array as &$row) { $params[] = &$row; } array_multisort(...$params); } array_multisort_custom($array, 'type', ['conference', 'journal']); var_export($array);
You have javascript disabled. You will not be able to edit any code.