https://www.php-resource.de/forum/php-developer-forum/87578-array-counting-problem