-1
People I have an associative array and would like to sort by single input with the sum of values. For example.
$product = ['Arroz branco' => 36,'Arroz parborizado' => 10, 'Arroz Integral' => 1, 'Açúcar' => 547, 'Açúcar refinado' => 10' , 'Feijao de corda' => 10, 'Feijão preto' => 15, 'FERMENTO' => 854];
The return should be:
$product = ['Arroz' => 47, 'Acucar' => 557, 'Feijao' => 25, 'Fermento' => 854 ];
I’m grateful for any help.
And what are the rules to define which are the same indexes? Always the first word? What if one is uppercase and the other lowercase?
– Woss
Just the first word. I can already handle all the uppercase and minuscule put them all only with the first letter Uppercase.
– Junior Oliveira
And why "Sugar" became "Sugar"?
– Woss
Retreat accentuation and cedilla.
– Junior Oliveira
Okay, have you tried anything? Do you have any idea how it can be done?
– Woss
I’ve tried everything, but I always lose information when I format the indexes.
– Junior Oliveira
@Junioroliveira see my answer. I know the code got ugly,.
– Maury Developer