php - Create a variable parameter list -


im looking bit of advice, have visited this page in manual, might wrong page or misinterpreted instructions still confused.

enter image description here

i have following question assignment above. know:

  1. 1st , foremost variable-length parameter?
  2. creating function not problem however, how set number of argumnets, since according question (if understand correctly) function should able take number of arguments. guess comes 1st question regarding variable-length paramenters again...?

thank reading

to use variable length parameters on php need function func_get_args() instead define parameters on function declaration. function this:

function foo() {     $params_count = func_num_args();     $params_values = func_get_args(); } 

on $params_values there parameters given foo() function. on params_count there number of parameters given foo(). can number of parameters given foo function func_num_args()

an example of using functions (https://3v4l.org/twd3v):

function foo() {     $params_count = func_num_args();     var_dump($params_count);     $params_values = func_get_args();     var_dump($params_values); } 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -