foreach uses a copy of this array, so the function will be executed only once.
foreach(explodecount(' ','A B C') as $v)
echo $v;
function explodecount($a,$b){
echo '@';
return explode($a,$b);
}
but this does not work:
foreach(explode(' ','A B C') as &$v)
echo $v;
Here you must save the exploded array in a separate variable.
source
share