group array by it's attribute
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
- ahmed31916
- Advanced
- Posts: 148
- Joined: 14 Apr 2022, 12:15
group array by it's attribute
Hello Aimeos,
For this array, how can I group it by it's attribute?
For this array, how can I group it by it's attribute?
Code: Select all
array:35 [▼
61 => Aimeos\MShop\Product\Item\Standard {#494 ▼
-available: true
-modified: false
-prefix: "product."
#bdata: array:20 [▶]
-date: "2022-06-20 07:37:00"
-listItems: array:1 [▶]
-listRefItems: array:1 [▼
"attribute" => array:1 [▼
21 => Aimeos\MShop\Attribute\Item\Standard {#541 ▶}
]
]
-listRmItems: []
-listPrepared: false
-listRmMap: []
-listMap: []
-listMax: 1
-propItems: []
-propRmItems: []
-propMax: 0
}
83 => Aimeos\MShop\Product\Item\Standard {#461 ▶}
62 => Aimeos\MShop\Product\Item\Standard {#464 ▶}
84 => Aimeos\MShop\Product\Item\Standard {#545 ▶}
63 => Aimeos\MShop\Product\Item\Standard {#465 ▶}
Re: group array by it's attribute
You can do something like this:
Code: Select all
$map = $products->getRefItems( 'attribute' )
->flat( 1 )
->getCode()
->flip()
->map( function( $val, $key ) use ( $products ) {
return $products->get( $val );
} );
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star