2015-04-07 60 views
2

我有这个阵列错误使用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']); });

但即时得到一个错误:未定义索引产品

+0

对数组排序时,只能根据最外层维排序。因此,$ a和$ b没有索引产品,它们具有索引0和1.并且在那里将产品 –

回答

1

试试这个: -

uasort($array, function ($a, $b) { 
    $i=0; 
    return strcmp($a[$i]['product'], $b[$i]['product']); 
}); 
+0

抱歉,而不是编辑,删除发生。但我转发了它。请看一看。 –

+0

这就是它,非常感谢你 – ihssan

+0

永远欢迎:) –