PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php $arr = [ 3 => ["id" => 1, "name" => "test", "exp" => [1 => "a"]], 4 => ["id" => 2, "name" => "test2", "exp" => [1 => "bb"]], 5 => ["id" => 3, "name" => "test", "exp" => [1 => "bb_ext"]], 6 => ["id" => 4, "name" => "test2", "exp" => [1 => "st"]], ]; //Массив по ключам которым должна идти сортировка $lmExpArr = [ "" => "-", "a" => "A", "b" => "B", "bb" => "Bb", "c" => "C", "st" => "Ст.", "a_ext" => "A (Доп)", "b_ext" => "B (Доп)", "bb_ext" => "Bb (Доп)", "c_ext" => "C (Доп)", "st_ext" => "Ст. (Доп)", ]; $sort_keys = array_keys($lmExpArr); print_r($sort_keys); usort( $arr, function($a, $b) use($sort_keys) { return array_search($a["exp"][1], $sort_keys) <=> array_search($b["exp"][1], $sort_keys); } ); print_r($arr);
Show:  
Copy Clear