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?
现在我想要一个包含所有数组的数组,其中key locale = de_DE!这可能吗?
1 个解决方案
#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");
#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");