public function testMultisortWithColumn() { $input = [["id" => "42", "name" => "Jakob", "age" => 37], ["id" => "43", "name" => "Topher", "age" => 18], ["id" => "43", "name" => "Allan"]]; $this->assertEquals([37, 18], array_column($input, "age")); $this->assertEquals([37, 18, null], arr_column($input, "age")); $this->assertEquals([["id" => "43", "name" => "Allan"], ["id" => "43", "name" => "Topher", "age" => 18], ["id" => "42", "name" => "Jakob", "age" => 37]], arr_multisort(arr_column($input, "age"), $input)[1]); }
public function testMultisort() { $input1 = [100, 1, 10, 1000]; $input2 = [1, 3, 2, 4]; $input3 = [1, 9, 4, 12]; $this->assertEquals([[1, 10, 100, 1000], [3, 2, 1, 4]], arr_multisort($input1, $input2)); $this->assertEquals([1, 10, 100, 1000], arr_multisort($input1)); $multidimensional = [$input1, $input3]; $this->assertEquals([[1, 10, 100, 1000], [9, 4, 1, 12]], arr_multisort($multidimensional[0], $multidimensional[1])); }