Ich arbeite mit einem mehrdimensionalen array.i möchte dieses Array von brand_id und cat_id gruppieren. Im folgenden Array [0], [1] und [2], [3] haben ähnliche brand_ids und cat_ids.i möchten product_ids entfernen und möchten die Summe von qtys in diesem Objekt erhalten.PHP: Funktion zum Gruppieren von Objekt-Array von Objekten Element
Array (
[0] => stdClass Object
(
[brand_id] => 1
[cat_id] => 1
[qty] => 150
[product_id] => 1
)
[1] => stdClass Object
(
[brand_id] => 1
[cat_id] => 1
[qty] => 250
[product_id] => 5
)
[2] => stdClass Object
(
[brand_id] => 4
[cat_id] => 35
[qty] => 100
[product_id] => 322
)
[3] => stdClass Object
(
[brand_id] => 4
[cat_id] => 35
[qty] => 200
[product_id] => 321
)
)
i möge Array neu anordnen ähnlichen
Array (
[0] => stdClass Object
(
[brand_id] => 1
[cat_id] => 1
[qty] => 400
)
[1] => stdClass Object
(
[brand_id] => 4
[cat_id] => 35
[qty] => 300
[product_id] => 322
)
)
ich Sie bei der Abfrage aussehen vorschlagen, die dieses Array erstellt, anstatt mit seinen Ergebnissen Hantieren – RiggsFolly
Was http://php.net/manual/en/function. usort.php – ceadreak
@ceadreak 'usort' dient zum Umordnen eines Arrays, es führt keine Elemente zusammen. – Barmar