是否有可能在php函数的include()中返回一个变量?


Is it possible to return a variable inside a include() in php function?

我有一个这样的函数

function test()
{
    include("test.php");
}
echo test();

test.php

<?php
//echo 'test1';
return 'test2';
?>

echo 'test1'工作,但return 'test2'不工作。

for me不返回任何值。

是的,这是可能的,但是您还需要从函数返回该值:

function test()
{
    return include("test.php");
}
echo test();