我有這個陣列錯誤使用uasort與多維數組:未定義指數
$array["4E-952778"][0]['fileName'] = "File 1";
$array["4E-952778"][0]['product'] = "Muse On Demand";
$array["4E-952778"][1]['fileName'] = "File 2";
$array["4E-952778"][1]['product'] = "Muse On Demand";
$array["15210"][0]['fileName'] = "File 3";
$array["15210"][0]['product'] = "4Manager";
$array["15210"][1]['fileName'] = "File 4";
$array["15210"][1]['product'] = "4Manager";
和我嘗試它使用uasort()
這樣排序:
uasort($array, function ($a, $b) { return strcmp($a['product'], $b['product']); });
但即時得到一個錯誤:未定義索引產品
對數組排序時,只能根據最外層維排序。因此,$ a和$ b沒有索引產品,它們具有索引0和1.並且在那裏將產品 –