Total amount of values in PHP array

1

I have this array down, and would like to know how I can count how many equal values it has in value[0] .

Array:

array(5) {
  [0]=>
  array(9) {
    [0]=>
    string(6) "500038"
    [1]=>
    string(6) "204932"
"
  }
  [1]=>
  array(9) {
    [0]=>
    string(6) "500038"
    [1]=>
    string(6) "204932"
"
  }
  [2]=>
  array(9) {
    [0]=>
    string(6) "100398"
    [1]=>
    string(6) "204932"
"
  }
  [3]=>
  array(9) {
    [0]=>
    string(6) "100398"
    [1]=>
    string(6) "204932"
"
  }
  [4]=>
  array(9) {
    [0]=>
    string(6) "100398"
    [1]=>
    string(6) "204932"
"
  }
}

For example, I know that you have 2 equal values that are 500038 and 3 that are 100398 . I need the total of both. The numbers in value[0] will vary not always being the same.

I would like a way to do this because I need these numbers to know the total quantity and the volume number.

My idea would be this:

    
asked by anonymous 08.11.2016 / 13:29

1 answer

2

See if you can.

<?php

$array[] = array(500038, 204932);
$array[] = array(100398, 204932);
$array[] = array(100398, 204932);
$array[] = array(500038, 204932);
$array[] = array(100398, 204932);


for ($i = 0; $i < count($array); $i++) {
    $volume[$i] = $array[$i][0];
}

$volumeContado = array_count_values($volume);

foreach ($volumeContado as $key => $value) {
    $novoArray[] = array("volume" => $key, "qtd" => $value);
}

var_dump($novoArray);

Output.

 array (size=2)
  0 => 
    array (size=2)
      'volume' => int 500038
      'qtd' => int 2
  1 => 
    array (size=2)
      'volume' => int 100398
      'qtd' => int 3
    
08.11.2016 / 14:09