- array_reduce: documentation ( source)
- array_filter: documentation ( source)
- str_split: documentation ( source)
- ord: documentation ( source)
<?php
$str = 'hello world';
$cnt = count(array_filter(str_split($str), function ($v) { return ord($v) % 3 == 0; }));
echo 'total count- '.$cnt . PHP_EOL;
$cnt = array_reduce(str_split($str), function ($c, $v) { return $c + (ord($v) % 3 == 0 ? 1 : 0); }, 0);
echo 'total count- '.$cnt . PHP_EOL;