Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Regrouper les tableaux associatifs d'un tableau

2 views
Skip to first unread message

argon71

unread,
Aug 31, 2022, 6:47:39 PM8/31/22
to
Bonjour,
Je cherche comment réaliser un regroupement de tableaux associatifs contenus
dans un tableau.

Voici un exemple de tableau que j''ai : <code>$tableau</code>
<code>
array (size=5)
0 =>
'id' => string '1'
'Qty' => int 1
'Color' => string 'red'
'Size' => int 40
1 =>
'id' => string '22'
'Qty' => int 1
'Color' => string 'orange'
'Size' => int 40
2 =>
'id' => string '1'
'Qty' => int 1
'Color' => string 'red'
'Size' => int 40
3 =>
'id' => string '18'
'Qty' => int 1
'Color' => string 'pink'
'Size' => int 40
4 =>
'id' => string '22'
'Qty' => int 1
'Color' => string 'orange'
'Size' => int 40
</code>

Si l'id, la color et la taille sont identiques, alors les deux tableaux
associatifs doivent être regroupés ensemble pour n'en faire qu'un avec la
quantité qui passe à 2 ( ou 3 ou 4, ...)
Je souhaite obtenir ceci :

<code>
array (size=3)
0 =>
'id' => string '1'
'Qty' => int 2
'Color' => string 'red'
'Size' => int 40
1 =>
array (size=4)
'id' => string '22'
'Qty' => int 2
'Color' => string 'orange'
'Size' => int 40
2 =>
array (size=4)
'id' => string '18'
'Qty' => int 1
'Color' => string 'pink'
'Size' => int 40
</code>

Je recherche donc une méthodologie sur comment faire. Et pourquoi pas un peu de
code à tester et assembler.
Merci d'avance à tous.
0 new messages