<?php $array = [ [ "id" => 1, "recipient" => "User", "userName" => "Max Mustermann", "locationName" => "Test Location" ], [ "id" => 2, "recipient" => "Location", "userName" => "Susi Mustermann", "locationName" => "Another Location" ], [ "id" => 3, "recipient" => "Location", "userName" => "Susi Mustermann", "locationName" => "Wow Much Location" ], [ "id" => 4, "recipient" => "User", "userName" => "Fritz Kalkbrenner", "locationName" => "Good Music" ], [ "id" => 5, "recipient" => "Location", "userName" => "Paul Kalkbrenner", "locationName" => null ], ]; usort($array,function($a,$b){ $sort2key = strtolower($a['recipient']).'Name'; return $a['recipient'] <=> $b['recipient'] ?: is_null($a['locationName']) <=> is_null($b['locationName']) ?: $a[$sort2key] <=> $b[$sort2key]; }); var_export($array);
You have javascript disabled. You will not be able to edit any code.