Search code examples
phpfunctionincluderequire

Using parameters of function in included file


Hey peeps I got a question about this in 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>

And this code works. So how? I am allowed to use the second parametar $b from the first php file in second php file. Is it because second php file is called from a function?

Thanks nerds! <3


Solution

  • Here is an answer by 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?"