Good afternoon, there is an array:

array(12) { [2]=> string(6) "802344" [3]=> string(6) "802344" [4]=> string(6) "802344" [5]=> string(6) "802344" [6]=> string(6) "802344" [7]=> string(6) "802344" [8]=> string(6) "802344" [9]=> string(6) "802344" [10]=> string(6) "802344" [11]=> string(6) "802335" [12]=> string(6) "802335" [13]=> string(6) "802347" } 

It is necessary to calculate how many times the value in a line matches and display the number and values ​​themselves as follows:

  [1]=> array(17) { ["id"]=> int(7) "802335" ["quantity"]=> int(27) "2" } [2]=> array(17) { ["id"]=> int(7) "802344" ["quantity"]=> int(27) "9" } [3]=> array(17) { ["id"]=> int(7) "802347" ["quantity"]=> int(27) "1" } 

    1 answer 1

    there is a specially trained function

     $ar1 = array_count_values($array); array_walk($ar1, function(&$v, $k) { $v = [ 'id'=>$k, 'quantity'=>$v]; }); print_r($ar1); 
    • Yes, it would be nice, I would be very grateful .... now I will read about the function))))) - Ivan Triumphov
    • updated answer with format conversion - splash58
    • and it helped. Responsive people on this resource live. Thank you very much !!! very much helped, the deadline is burning ..... he himself would still be stupid - Ivan Triumphov
    • glad what happened. good luck - splash58