<?php
$array = [
"T3497012@CHOSTBRHDDSB@EICM_BORA@BPHS@Bamz",
"T3497012@BHOSTBRHDDSB@EICM_BORA@BPHS@Bamz",
"T3497012@AHOSTBRHDDSB@EICM_BORA@BPHS@Bamz",
"T3497012@AHOSTBRHDDSB@EICM_BORB@BPHS@Aama",
"T3497012@AHOSTBRHDDSB@EICM_BORC@APHS@cama",
"T2497123@DHOSTBRHDDSB@CICM_BORD@APHS@camb",
"T2497123@EHOSTBRHDDSB@BICM_BORE@APHS@camc",
"T5557012@FHOSTBRHDDSB@AICM_BORF@APHS@camd"
];
foreach ($array as $chave => $valor){
$array[$chave] = explode("@",$valor); }
usort($array, function($a, $b){
if ($a[2] === $b[2]){
if ($a[3] === $b[3]){
if ($a[4] === $b[4]){
}
else return strcmp($a[4], $b[4]); }
else return strcmp($a[3], $b[3]); }
else return strcmp($a[2], $b[2]);
});
foreach($array as $chave => $valor){
$array[$chave] = implode("@", $array[$chave]); }
PD9waHAKCiRhcnJheSA9IFsKICAgICAgICAiVDM0OTcwMTJAQ0hPU1RCUkhERFNCQEVJQ01fQk9SQUBCUEhTQEJhbXoiLAogICAgICAgICJUMzQ5NzAxMkBCSE9TVEJSSEREU0JARUlDTV9CT1JBQEJQSFNAQmFteiIsCiAgICAgICAgIlQzNDk3MDEyQEFIT1NUQlJIRERTQkBFSUNNX0JPUkFAQlBIU0BCYW16IiwKICAgICAgICAiVDM0OTcwMTJAQUhPU1RCUkhERFNCQEVJQ01fQk9SQkBCUEhTQEFhbWEiLAogICAgICAgICJUMzQ5NzAxMkBBSE9TVEJSSEREU0JARUlDTV9CT1JDQEFQSFNAY2FtYSIsCiAgICAgICAgIlQyNDk3MTIzQERIT1NUQlJIRERTQkBDSUNNX0JPUkRAQVBIU0BjYW1iIiwKICAgICAgICAiVDI0OTcxMjNARUhPU1RCUkhERFNCQEJJQ01fQk9SRUBBUEhTQGNhbWMiLAogICAgICAgICJUNTU1NzAxMkBGSE9TVEJSSEREU0JAQUlDTV9CT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