Page 1 of 1

Sortieren Sie ein 2D -Array in PHP nach einer Spalte

Posted: 01 Feb 2025, 06:17
by Anonymous
Ich versuche, JSON -Array nach Schlüssel in PHP zu sortieren. Obwohl ich usort < /b> benutze, funktioniert es nicht.$data = [
{
"profile_name": "J3S",
"post_count": 9
},
{
"profile_name": "John",
"post_count": 3
},
{
"profile_name": "sato",
"post_count": 10
}
]
< /code>

Ich möchte das Array nach post_count sortieren.

Hier ist mein Code, den ich ausprobiert habe. < /p>

$data = json_encode($data, true);

usort($data, function ($a, $b) {
return $a['post_count'] $b['post_count'];
});
< /code>

Könnten Sie mir bitte helfen? < /p>