Can you explain the algorithm provided in the forum thread for determining array dimensions in PHP?

The algorithm provided in the forum thread aims to determine the dimensions of a multidimensional array in PHP. This can be achieved by recursively iterating through the array and counting the number of elements at each level. By keeping track of the maximum count encountered at each level, we can determine the dimensions of the array.

function getArrayDimensions($array) {
    if (!is_array($array)) {
        return false;
    }
    
    $dimensions = [];
    $dimensions[] = count($array);
    
    if (is_array($array[0])) {
        $subDimensions = getArrayDimensions($array[0]);
        $dimensions = array_merge($dimensions, $subDimensions);
    }
    
    return $dimensions;
}

// Example usage
$array = [[1, 2], [3, 4, 5]];
$dimensions = getArrayDimensions($array);
print_r($dimensions);