请考虑以下多维数组结构:
$products = [
[
'name' => 'Item 1',
'type' => 'shoes'
],
[
'name' => 'Next Day (DPD)',
'type' => 'shipping'
],
[
'name' => 'Levis 501',
'type' => 'jeans'
]
];
我想做的是始终对数组进行排序,以便将type
中shipping
与$products = [
[
'name' => 'Item 1',
'type' => 'shoes'
],
[
'name' => 'Levis 501',
'type' => 'jeans'
],
[
'name' => 'Next Day (DPD)',
'type' => 'shipping'
]
];
的项目放在数组的末尾(在数组),然后按字母顺序对所有内容进行排序。
我想要的输出如下:
usort($products, function($a, $b) {
if( $a['type'] == 'shipping' || $b['type'] == 'shipping' )
{
return -1111;
}
return 1;
});
我尝试了以下操作,但是它不能按预期方式工作,并且无法对数组进行相应的排序:
Warning: session_start(): open(/var/lib/php/session/sess_ikk0j7e15bveibgk0crj508ki5, O_RDWR) failed: Permission denied (13) in /var/www/html/setup.php on line 26
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/session) in /var/www/html/setup.php on line 26