How to define Variable Scope in Php?
If you define a variable within a function that means variable is only available within that function. This variable cannot CALL in another function or in the body of your program code. These types of variable are known as a variable's scope. The scope of a variable defined within a function is local to that function. If you want to use variable that is defined in the main body of program code. Remember It must reference using global keyword.
function_SubNumber ( )
global $sum = 4 - 4
$sum = 0
Subnumber ( )
echo "4 - 4 = ".$sum
You're not really asking anything - or anything that is clearly a question.
So to actually answer your question: scope is defined by the context in which you have declared your variables.
The code itself, is completely useless. The function signature is incorrect, it has no semi-colon delimiters, and the use of global is entirely incorrect (global is *not* an assignment operation). So many a syntax errors this has.
This does kind of raise question as to why this thread was posted in the first place though. . .
|All times are GMT +1. The time now is 05:04 PM.|
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.