There is such a user function:
function subarr_cout () { $s = 0; $al = func_num_args(); $vl = count(func_get_args(0)); for ($a = 1; $a < $al; $a++) { $il = count(func_get_args($a)); for ($i = 0; $i < $il; $i++) { for ($v = 0; $v < $vl; $v++) { if (func_get_args($a)[$i] == func_get_args(0)[$v]) $s++; } } } return $s; } It receives, as arguments, a certain number of arrays, the first of which contains data for comparison, and the second and subsequent arrays are checked for the presence of matches in them.
There is a playing field of 10x10 cells, the data about which is stored in the corresponding two-dimensional array. I need to calculate how many cells of a certain type are in the whole field.
The function was assumed to be universal, for counting the number of matches in any array, and I don’t really want to rewrite it to check the two-dimensional array.
The obvious solution is to rewrite the function to get two arrays, the second of which will contain arrays to check, or enter another required argument indicating the depth of the dive, but I'm not sure that this is the best option.
Therefore, the question is: Is there no way to pass all the elements of an array to a function as independent arguments? There is a list() function, but it will simply turn an array of ten elements into ten separate variables, which you will still have to pass functions manually, as if I simply listed all the elements of the array. I would like something more elegant, especially since I am almost sure that there is such a solution, I just did not find it.