I have the following PHP code which uses foreach and gives the correct count. This is what I tried with loop.
$str = 'hello world';
$cnt = 0;
$arr = str_split($str);
foreach($arr as $val){
if( ord($val)%3 == 0 ){
$cnt++;
}
}
echo 'total count- '.$cnt; //count is 6 here which is correct
Is there a way of doing the same thing in PHP
without the use of loops or recursion?