I want to have few optional arguments in PHP function, how do i go with it, Its optional and not the default.

Thanks
🆒

    First idea is to have all the variables you need with default values
    like

    function my_func($var1, $optvar2 = 'a', $optvar3 = 'b', $optvar3 = 'c')
    

    but it's not very suitable.

    Another way is to pass optional variables as array:

    function my_func1 ($var1, $opt_var_array)
    

    and then look for array members.

      Write a Reply...