Skip to content

Instantly share code, notes, and snippets.

@Mahno74
Created August 26, 2021 09:23
Show Gist options
  • Save Mahno74/80b0d502b24912dbb3a7731f213c17a5 to your computer and use it in GitHub Desktop.
Save Mahno74/80b0d502b24912dbb3a7731f213c17a5 to your computer and use it in GitHub Desktop.
Неопределенное количесво аргументов функции
<?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