Although strings may be iterated using for
loops and indexes, they can't be iterated using foreach
loops. Example:
$str = 'foo';
$max = strlen($str);
for ($i=0; $i<$max; $i++) {
echo $str[$i];
}
// outputs: foo
foreach ($str as $char) {
echo $char;
}
// Warning: Invalid argument supplied for foreach() ...