how to pass a variable through the require() or include() function of php?

后端 未结 9 2086
梦如初夏
梦如初夏 2021-02-06 21:34

when I use this:

require(\"diggstyle_code.php?page=$page_no\");

the warning is :failed to open stream: No error in C:\\xampp\\htdocs\\4ajax\\ga

9条回答
  •  北海茫月
    2021-02-06 22:32

    Though this question is old there's another option that I use which is missing from this thread. You can return a function from the required file which accepts the arguments you want to pass along:

    return function(array $something) {
        print_r($something);
    }
    

    And call it with the arguments when you require it:

    require('file.php')(['some', 'data']);
    
    // or:
    
    $context = require('file.php');
    $context(['some', 'data']);
    

提交回复
热议问题