For example, below is the data I read from the database, and then I want to rearrange this Array Based on suppliers_id. What is a better method? {Code ...} changed to {code ...} for example, below is the data I read from the database, and then I want to rearrange this Array Based on suppliers_id. What is a better method?
[{Cart_id: "6", suppliers_id: "1", goods_name: "commodity 1" ,}, {cart_id: "7", suppliers_id: "1", goods_name: "product 2" ,}{ cart_id: "7", suppliers_id: "1", goods_name: "Product 3",}]
Change
[// Suppliers_id 1: [{cart_id: "6", suppliers_id: "1", goods_name: "item 1" ,}, {cart_id: "7", suppliers_id: "1", goods_name: "commodity 3",}] // suppliers_id 2: [{cart_id: "7", suppliers_id: "1", goods_name: "product 2",}]
Reply content:
For example, below is the data I read from the database, and then I want to rearrange this Array Based on suppliers_id. What is a better method?
[{Cart_id: "6", suppliers_id: "1", goods_name: "commodity 1" ,}, {cart_id: "7", suppliers_id: "1", goods_name: "product 2" ,}{ cart_id: "7", suppliers_id: "1", goods_name: "Product 3",}]
Change
[// Suppliers_id 1: [{cart_id: "6", suppliers_id: "1", goods_name: "item 1" ,}, {cart_id: "7", suppliers_id: "1", goods_name: "commodity 3",}] // suppliers_id 2: [{cart_id: "7", suppliers_id: "1", goods_name: "product 2",}]
The tag isphp
It indicates powerless.
You can usesort(function(a,b){})
This approach comes.
The uksort function of PHP can receive two parameters.
$arr = [{c:"213"},{c:"dadad"}]function compare_func($a, $b){ return $a=>c - $b=>c;}uksrot($arr,"compare_func" );