P
P
Pavel2020-04-23 15:51:24
PHP
Pavel, 2020-04-23 15:51:24

How to find out how many times each element of an array is repeated?

I have such an array for example

the array itself

array(1612) {
  [0]=>
  array(1) {
    ["user_id"]=>
    string(2) "37"
  }
  [1]=>
  array(1) {
    ["user_id"]=>
    string(2) "58"
  }
  [2]=>
  array(1) {
    ["user_id"]=>
    string(2) "58"
  }
  [3]=>
  array(1) {
    ["user_id"]=>
    string(2) "21"
  }
  [4]=>
  array(1) {
    ["user_id"]=>
    string(2) "41"
  }
  [5]=>
  array(1) {
    ["user_id"]=>
    string(2) "58"
  }
  [6]=>
  array(1) {
    ["user_id"]=>
    string(3) "110"
  }
 
  [190]=>
  array(1) {
    ["user_id"]=>
    string(2) "69"
  }

  [1093]=>
  array(1) {
    ["user_id"]=>
    string(2) "70"
  }
  [1094]=>
  array(1) {
    ["user_id"]=>
    string(2) "70"
  }
  [1095]=>
  array(1) {
    ["user_id"]=>
    string(2) "70"
  }
  [1096]=>
  array(1) {
    ["user_id"]=>
    string(2) "70"
  }
}



he has these ["user_id"] repeated many times, how to get an array where everything will be added?
I tried the array_count_values ​​function, but something doesn't work

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FanatPHP, 2020-04-23
@FanatPHP

Because array_count_values ​​works on a one-dimensional array.
Therefore, you must first google, "how to get a one-dimensional array from a two-dimensional array" or "how to get one column from a two-dimensional array"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question