使用包含文件中的函数参数
Using parameters of function in included file
大家好,我在 PHP 中收到了关于此的问题。
first_file.php
<?php
function myFunction($a,$b){
include 'second.php';
echo $a;
}
myFunction(5,['Name'=>'Stefan']);
second_file.php
<h1><?php echo $b['Name']?></h1>
并且此代码有效。又怎样?我可以在第二个 php 文件中使用第一个 php 文件中的第二个参数 $b。是因为第二个 php 文件是从函数调用的吗?
谢谢书呆子! <3
这是 Patrick Q 的回答
"Think of it as if the content from 'second.php' were copy/pasted to where the include line is. Would you understand how it works then?"
大家好,我在 PHP 中收到了关于此的问题。
first_file.php
<?php
function myFunction($a,$b){
include 'second.php';
echo $a;
}
myFunction(5,['Name'=>'Stefan']);
second_file.php
<h1><?php echo $b['Name']?></h1>
并且此代码有效。又怎样?我可以在第二个 php 文件中使用第一个 php 文件中的第二个参数 $b。是因为第二个 php 文件是从函数调用的吗?
谢谢书呆子! <3
这是 Patrick Q 的回答
"Think of it as if the content from 'second.php' were copy/pasted to where the include line is. Would you understand how it works then?"