I executed following code but php says:
Notice: Undefined variable: b in ..\..\..\demo.php on line 4
Notice: Undefined variable: a in ..\..\..\demo.php on line 4
Php Code:
<?php
$a='a';$b='b';
function test(){
echo $a.$b;
}
test(); // error
?>
But i changed the code to this:
<?php
$a='a';$b='b';
function test($a,$b){
echo $a.$b;
}
test($a,$b); // ab
?>
Why $a and $b are undefined in first case, since i defined them before?
Why parameters need to pass in php? It's not require in other like JavaScript.
global $a, $b;in your first function and it will work :)