-1

How can I sort the following array:

$members = [
  0 => [
    "name" => "Steve",
    "privilege" => "admin"
  ],
  1 => [
    "name" => "Lisa",
    "privilege" => "editor"
  ],
  2 => [
    "name" => "Eric",
    "privilege" => "owner"
  ]
]

Based on the order of this array:

$privileges = ['owner', 'admin', 'editor'];

So I end upp with the first array with the items listed Eric, Steve, Lisa

SeaBass
  • 1,322
  • 2
  • 15
  • 41
  • Maybe [something like this](https://3v4l.org/MV9H2)? I would suggest, if you're using a database, to `order by` in your SQL instead. – Jaquarh Jun 02 '22 at 08:52
  • Thanks! I’ll try this in a bit! I’m not using a database in this case. – SeaBass Jun 02 '22 at 09:14
  • @Jaquarh Thank you so much! That is close, but it adds an array level to each original array. Any way to get around that? Thanks!! – SeaBass Jun 02 '22 at 16:20
  • I think this fixes that issue, but let me know if you have a better idea. `$members = array_merge([], ...$members);` – SeaBass Jun 02 '22 at 16:49
  • Or see the duplicate linked above… – deceze Jun 02 '22 at 16:56

0 Answers0