1

I have following array

Array
(
     [0] => Array(
         [0] => Water
         [1] => 0.5555)
     [1] => Array(
         [0] => Jojoba Oil
         [1] => 1)
     [2] => Array(
         [0] => Water
         [1] => 0.3)
     [3] => Array(
         [0] => Coconut Extract
         [1] => 1.2)
     [4] => Array(
         [0] => Walnut Extract
         [1] => 1.1)
     [5] => Array(
         [0] => Water
         [1] => 0.5555)
     [6] => Array(
         [0] => Peptide 1
         [1] => 2)
     [7] => Array(
         [0] => Preservative
         [1] => 0.5555)
)

And I need the following output(by adding the value of repetitive key and display once e.g 'Water')

Array(
[Peptide 1] => 2 
[Water] => 1.411 
[Coconut Extract] => 1.2 
[Walnut Extract] => 1.1 
[Jojoba Oil] => 1 
[Preservative] => 0.5555
)

var dump output:- var dump output

and also sort by the sum in desc order Thanx in advance...

Sachin Kumar
  • 3,001
  • 1
  • 22
  • 47
  • can you paste `var_dump` of the array? – Agam Banga May 21 '17 at 07:57
  • 6
    Possible duplicate of [Associative array, sum values of the same key](http://stackoverflow.com/questions/14195916/associative-array-sum-values-of-the-same-key) – RomanPerekhrest May 21 '17 at 08:01
  • 1
    also consider the following : [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) we don't have to convert your var_dump output to an executable array. :-) – hassan May 21 '17 at 08:03

0 Answers0