How do I transmit multiple custom functions? Function & nbsp; a () {} function & nbsp; B () {} function & nbsp; c () {} function & nbsp; demo (parameter) {& nbsp; // sometimes a (), B (), and c ()} demo (parameter) are used. My question is, how can I pass a function as multiple custom functions?
Function (){}
Function B (){}
Function c (){}
Function demo (parameter ){
// Sometimes use a (), sometimes B (), and sometimes c ()
}
Demo (parameter );
My question is, can a function be passed as a parameter?
If yes, what is the writing method?
Please advise...
------ Solution --------------------
Can the function be passed as a parameter at the end of this post edited by xuzuning at 16:06:55?
Yes!
// No other parameters
Function demo ($ func ){
$ Func ();
}
// Example
Demo ('A ');
// There are a fixed number of parameters, such as two
Function demo ($ func, $ p1, $ p2 ){
$ Func ($ p1, $ p2 );
}
// Example
Demo ('B', 2, 4 );
// There are variable quantity parameters
Function demo (){
$ T = func_get_ags ();
$ Func = array_shift ($ t );
Call_user_func_array ($ func, $ t );
}
// Example
Demo ('C', 2, 4, 'A', 'B', 'C ');