[Solved] Count an array php


While this question is poorly worded, I think I understand what you are asking for. Here’s what you should do. I am not all that fluent in php so please make sure that you look over the code snippets that I write instead of copy/pasting them.

  1. Find the maximum X and Y values.
  2. Instantiate and initialize a 2D array based on those values divided by 50.

For instance if you wanted Array[X][Y] you would do:

$myArray = array();
for ($x = 0; $x < $maxX / 50; $x++) {
    $myArray[] = array();
    for ($y = 0; $y < $maxY / 50; $y++) {
        $myArray[$x][] = 0;
    }
}

This should instantiate and initialize a 2D array to all 0’s just like you need

3) Iterate through your array and for each entry, increment the value of $myArray[$curX/50][$curY/50] by 1:

foreach ($inputArray as $curRow) $myArray[$curRow[b]/50][$curRow[a]/50] += 1;

Again, I’m no pro at php and have really just started working with it, but this should be a good start.

2

solved Count an array php