New course! Every coder should learn Generative AI!
Try a free lesson+ 2
Try:
$numberOfElements = count($arr, COUNT_RECURSIVE);
The count() function counts recursively with a second parameter set to 1 or COUNT_RECURSIVE.
See also here https://www.php.net/manual/en/function.count.php