Following a Tutorial I am struggling with an issue in a PHP function. I have some basic background on C# and Java and according to my knowledge this code shouldn't work since I am not passing any parameter in the add() function, but , surprisingly!, it works!
According to PHP Manual the func_num_args() Gets the number of arguments passed to the function.so how we can echo the result of the add() function while we are not passing any parameter in the function?! Also, if the function is for getting the number of arguments how we can use it to calculate the numbers?!
<?php
function add(){
$args = func_num_args();
$sum = 0;
$i = 0;
for($i; $i< $args; $i++ ){
is_int(func_num_args($i)) ? $sum+= func_num_args($i) : die('Use Only Numbers');
}
}
echo add(2,5,10,12);
?>
Thanks for your comments