Ok, this is cheating, but eventually I did this:
$tags = getSomeTags();
$tags_eng = $tags_lang = [];
foreach ($tags as $tag => $value) {
if ($tag[0] <= 'z') $tags_eng[$tag] = $value;
else $tags_lang[$tag] = $value;
}
ksort($tags_eng); ksort($tags_lang);
$tags = $tags_lang + $tags_eng;
Array "union" operation maintains the order of elements, so that works well.
Please note that its important not to use array_merge()
for concatenating the arrays at the end, because if you have string keys that look like a number (compare "9"
with 9
), then array_merge()
will think its an "indexed item" and will do weird stuff with it (resetting the key to the earliest available index).
I'd love it if someone can come up with a better method.