1

Good day.

Code:

array(4) { 
    [0]=> array(1) { 
          [0]=> array(3) { 
               [0]=> string(11) "art_7880" [1]=> string(1) "1" [2]=> int(2950) 
          }
          [1]=> array(3) { 
               [0]=> string(8) "art_7880" [1]=> string(1) "1" [2]=> int(2955)  
          } 
          [2]=> array(3) { 
               [0]=> string(8) "art_7880" [1]=> string(1) "1" [2]=> int(1335)  
          }
          [3]=> array(3) { 
               [0]=> string(8) "art_7883" [1]=> string(1) "1" [2]=> int(4335)  
          }
}

I get array unique elements:

$arr_uniq = array();
foreach ($all_array as $keys => $elms ) {
    if(!in_array($elms[0], $arr_uniq)) {
        $arr_uniq[] = $elms[0];
    }
}

Tell me pleasse how to get a count each unique element in the general array?

result should been next:

art_7880 - 3

art_7883 - 1

2 Answers 2

4

Assuming $all_array is subarray of your main array in your var_dump snipett, the general idea is

$result = array();
foreach ($all_array as $elms)    
    $result[$elms[0]]++;    
Sign up to request clarification or add additional context in comments.

Comments

0

array_count_values()

http://php.net/array_count_values

You should be able to easily apply this function.

1 Comment

Jessica, please explain. i get array with all unique elements. what step i should make next?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.