0

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?

1
  • 1
    Using usort(), yes it is Commented Apr 9, 2014 at 9:58

1 Answer 1

1

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");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.