Created
August 26, 2021 09:23
-
-
Save Mahno74/80b0d502b24912dbb3a7731f213c17a5 to your computer and use it in GitHub Desktop.
Неопределенное количесво аргументов функции
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getSum(){ | |
//Если аргументов не передано возвращаем false | |
if (func_num_args()==0) return false; | |
$count = 0; | |
//func_get_arg($i) позиция аргумента в массиве всех переданных аргументов | |
for ($i=0; $i<func_num_args(); $i++){ | |
$count +=func_get_arg($i); | |
} | |
return $count; | |
} | |
$a = getSum(1, 3, 8); | |
echo "$a"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment