I'm trying to do something like this
$level=0;
if($a=="x"){
$level=1;
}
Else{ $level=2;}
How I can use the new value of $level outside the scope of IF Statement
Once you get through the IF statement the new value, for the $level variable, will be valid for the remaining code:
$level = 0;
echo $level; # outputs: 0
# for the example, random choice
$a = rand(1, 2);
if($a == 1)
$level = 1;
else
$level = 2;
echo $level; # outputs: 1 or 2, nevermore 0
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.