Variables Defined Outside Functions Are Inaccessible from Within a Function by Default : Variable Scope « Language Basics « PHP






Variables Defined Outside Functions Are Inaccessible from Within a Function by Default





<html>
<head>
<title>Variables Defined Outside Functions Are Inaccessible from Within a Function by Default</title>
</head>
<body>
<?php

$life = 42;

function meaningOfLife(){
     print "The meaning of life is $life<br>";
}

meaningOfLife();

?>
</body>
</html>

           
       








Related examples in the same category

1.Variable scope: function
2.Use variable defined outside function
3.Scope of a Variable
4.Variable Scope: A Variable Declared Within a Function Is Unavailable Outside the Function
5.Defining Variable Scope
6.More Working with Variable Scope
7.local variables
8.Variable Scope
9.Variable Scope in Functions
10.Variable Scope: A Variable Declared Within a Function Is Unavailable Outside the Function