what’s different between this two,
why when I use func_get_args
foreach only echo last number “7”
function add(){
$total=func_get_args();
foreach($total as $result);
echo $result;
}
add(1, 5 , 6, 7);
//////////////////////////////////////////////////////////////////
$array=array(1, 5, 6, 7);
foreach($array as $result){
echo $result;
}
For a start you are doing nothing with the foreach loop
What’s happening is the last
$resultis left and is echo’d by the next line.You could actually rewrite the add function like so:
Which is cooler imho 😉 (but doesn’t check for string values and such)