Question

I have an array like this:

[
   ['translationID'] => 1,
   ['locale'] => 'nl_BE',
   ['translation'] => 'U bent aangemeld'
]
[
   ['translationID'] => 2,
   ['locale'] => 'de_DE',
   ['translation'] => 'Sie sind angemeldet als'
]

Now I want an array with all the arrays where key locale = de_DE first! Is this possible?

Was it helpful?

Solution

Try this,

$arr = array(
        array("translationID" => "1","locale" => "nl_BE","translation" => "U bent aangemeld"),
        array("translationID" => "2","locale" => "de_DE","translation" => "Sie sind angemeldet als")
        );

function cmp($a, $b) {
    if ($a["locale"] == $b["locale"]) {
            return 0;
    }
    return ($a["locale"] < $b["locale"]) ? -1 : 1;
}
usort($arr,"cmp");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top