Setting a function equal a variable?

后端 未结 3 1229
不思量自难忘°
不思量自难忘° 2021-01-29 06:20

I have a PHP function and I want it to equal a variable. Here is the code:

 
相关标签:
3条回答
  • 2021-01-29 06:44

    You can't make a function equal a variable, but how about a variable that equals a function?

    $ItsaFunction = function() {
        //Code goes here
    };
    

    You could also do

    function ItsaFunction() {
        //Code goes here
    }
    
    $ItsaFunction = ItsaFunction(); 
    
    0 讨论(0)
  • 2021-01-29 06:46

    If I understand what to mean you want to check if there is a match in variables.

    <?php  
    
     $letter = 'a';
     $word = 'a';
    
     function ItsaFunction($first, $sec){
    
    if($first == $sec){
    
    echo 'match';
    
    }else{
    //do something
    }
    
    ItsaFunction($letter,$word);
    
    }
    ?>
    
    0 讨论(0)
  • 2021-01-29 06:52
    function foo() {
        echo "In foo()<br />\n";
    }
    
    $func = 'foo';
    $func();        // This calls foo()   
    
    0 讨论(0)
提交回复
热议问题