Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php textfile=file(“filepath.txt”)-如何返回文件数组?_Php_File_Return Type - Fatal编程技术网

php textfile=file(“filepath.txt”)-如何返回文件数组?

php textfile=file(“filepath.txt”)-如何返回文件数组?,php,file,return-type,Php,File,Return Type,在我最后一个关于这一点的问题完全有缺陷之后,一个新的尝试。版主将尽快删除旧问题 我正在从index.php调用一个函数gather\u info($host\u object)。此函数读取 在文本文件中使用file()-方法。当我在函数中使用print\u r进行打印时 用于调试的内容它工作正常 但是(在本例中)3个变量不能从index.php访问。它们是未定义的。 我尝试过使用“返回”值,但它不起作用 index.php: gather_info($host_object); for($i=0

在我最后一个关于这一点的问题完全有缺陷之后,一个新的尝试。版主将尽快删除旧问题

我正在从index.php调用一个函数gather\u info($host\u object)。此函数读取 在文本文件中使用file()-方法。当我在函数中使用print\u r进行打印时 用于调试的内容它工作正常

但是(在本例中)3个变量不能从index.php访问。它们是未定义的。 我尝试过使用“返回”值,但它不起作用

index.php:

gather_info($host_object);
for($i=0;$i<count($in);$i++){

}

当我读入index.php中的文件时,它也可以正常工作。任何提示?

返回中止函数的执行并立即返回调用上下文。你不可能有那样的多次返回——第二次和进一步返回到的操作几乎不可能执行

您可以进行一次
return
调用并返回元素数组,例如

function gather_info(...) {
   ...
   return array($in, $in2, $in3);
}

$foo = gather_info(...);
$in = $foo[0];
$in2 = $foo[1];
etc...

return
中止函数的执行,并立即返回调用上下文。你不可能有那样的多次返回——第二次和进一步返回到的操作几乎不可能执行

您可以进行一次
return
调用并返回元素数组,例如

function gather_info(...) {
   ...
   return array($in, $in2, $in3);
}

$foo = gather_info(...);
$in = $foo[0];
$in2 = $foo[1];
etc...

3倍回报?这可能吗?这有意义吗?没有。这是漫长的一天。我以前有返回数组($in1,in*,…),但不知道如何访问它。3倍返回?这可能吗?这有意义吗?没有。这是漫长的一天。我以前有返回数组($in1,in*,…),但不知道如何访问它。新问题,仍然粘贴错误。我以前有返回数组(…),但不知道如何处理它。我试试看。非常感谢。好啊新问题,仍然粘贴错误。我以前有返回数组(…),但不知道如何处理它。我试试看。非常感谢。