$key, 'pair' => $pair]; } if (empty($kept)) return ''; // Stable alphabetical sort on key. APO sorts the same way so // ?b=1&a=2 → ?a=2&b=1 on both sides. usort($kept, static fn($x, $y) => strcmp($x['key'], $y['key'])); return implode('&', array_map(static fn($k) => $k['pair'], $kept)); } }