To encapsulate a function with a function similar to the join (implode alias), the code is as follows: {code ...} in this way, the join operation is similar to that of the system function. However, if the $ glue parameter is not specified during the call, an error is returned. I know that parameters with default values should be placed behind them, such as getJoin ($ arr, $ gl...
To encapsulate a function with a function similar to the join (implode alias), the code is as follows:
$ Value) {$ str. = $ value. $ glue;} $ str = substr ($ str, 0,-1); return $ str;} echo getJoin (",", $ arr );
In this way, the join operation is similar to that of the system function. However, if the $ glue parameter is not specified during the call, an error is returned.
I know that parameters with default values should be placed behind them, for examplegetJoin($arr,$glue="")In this way, only the $ arr parameter can be filled in. However, after reading the manual, the system function join parameter value is as follows:
No brackets indicate that the parameter cannot be omitted. at the same time, it also supports writing only one parameter and uses an empty string as the $ glue value by default. Although there are some historical reasons, I still want to know how the system functions are implemented.
Reply content:
To encapsulate a function with a function similar to the join (implode alias), the code is as follows:
$ Value) {$ str. = $ value. $ glue;} $ str = substr ($ str, 0,-1); return $ str;} echo getJoin (",", $ arr );
In this way, the join operation is similar to that of the system function. However, if the $ glue parameter is not specified during the call, an error is returned.
I know that parameters with default values should be placed behind them, for examplegetJoin($arr,$glue="")In this way, only the $ arr parameter can be filled in. However, after reading the manual, the system function join parameter value is as follows:
No brackets indicate that the parameter cannot be omitted. at the same time, it also supports writing only one parameter and uses an empty string as the $ glue value by default. Although there are some historical reasons, I still want to know how the system functions are implemented.
Function overload...
Http://m.blog.csdn.net/articl...
If you must achieve this, you can use the php variable parameter quantity declaration method. See
Http://php.net/manual/zh/func...
Get the parameter to the array and process it by analyzing the array.