0

I have made following program -

<?php
global $a;
$a= "me";
echo $a;
function myname() {
echo $a;
}

myname();

?>

First echo works but second (inside the function) says undefined variable a

What is wrong?

  • This is not program? – Ayyanar G Mar 19 '15 at 08:16
  • 1
    You need to indicate that $a is a global variable ___inside___ your function: ` $a= "me"; echo $a; function myname() { global $a; echo $a; } myname(); ` not specify that it is global ___outside___ – Mark Baker Mar 19 '15 at 08:17

0 Answers0