PHP call_user_func vs. just calling function

前端 未结 8 1563
我寻月下人不归
我寻月下人不归 2020-12-04 08:06

I\'m sure there\'s a very easy explanation for this. What is the difference between this:

function barber($type){
    echo \"You wanted a $type haircut, no         


        
8条回答
  •  离开以前
    2020-12-04 08:45

    I imagine it is useful for calling a function that you don't know the name of in advance... Something like:

    switch($value):
    {
      case 7:
      $func = 'run';
      break;
      default:
      $func = 'stop';
      break;
    }
    
    call_user_func($func, 'stuff');
    

提交回复
热议问题