Php writing a function with unknown parameters?

后端 未结 4 1706
终归单人心
终归单人心 2020-12-20 17:07

How would I go about writing a function in php with an unknown number of parameters, for example

function echoData (parameter1, parameter2,) {
    //do somet         


        
4条回答
  •  一生所求
    2020-12-20 17:31

    func_get_args()

    function echoData(){
        $args = func_get_args();
    }
    

    Be aware that while you can do it, you shouldn't define any arguments in the function declaration if you are going to use func_get_args() - simply because it gets very confusing if/when any of the defined arguments are omitted

    Similar functions about arguments

    • func_get_arg()
    • func_get_args()
    • func_num_args()

提交回复
热议问题