0

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

4
  • 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?
    – Patrick Q
    Commented Mar 19, 2018 at 21:03
  • Yes, thanks bro! Can you please post that as answer so other could see better this? :))
    – user6912198
    Commented Mar 19, 2018 at 21:09
  • Honestly, a good reading of the documentation would answer your question, and include more detail. I was simplifying it so that you could figure it out yourself. It's not exactly the same as if it were copy/pasted, especially in this case where you are including some non-PHP content (if copy/paste logic were used, you'd be getting errors).
    – Patrick Q
    Commented Mar 19, 2018 at 21:22
  • Okay, thanks for advice! :)
    – user6912198
    Commented Mar 19, 2018 at 21:25

1 Answer 1

0

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?"


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.