What are the best practices for passing multiple variables to a function using PHP [closed]
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a function that takes 5 parameters, and as the application grew we needed to add few more parameters which ended up in 9 parameters with 4 of them having default values. I was wondering is it better to pass parameters like this or use an array? I prefer to have it like this fun(array( 'par1' => 'x', 'par2' => 'y', ..... ) ) Insted of func($par1, $par2, $par3, ...); What do you think? 回答1: Highly depends on the use case. But here are some solutions to this problem. Fixed Order If the order is somewhat fixed and you never have a need to