$j = 5;
$k = 10;
if ($j < $k){
print "Variable $j value is less than $k";
}
We can add ELSE condition to the above statement and that part will be executed
once the if condition does not satisfy. $j = 10;
$k = 5;
if ($j < $k){
print "Variable $j value is less than $k";
// This line will not be executed
}
else{
print "Variable $j value is greater than $k";
// This line will be executed
}
$j=8;
$k=5;
if($j<$k){
echo " Variable \$j $j value is less than \$k $k";
}elseif($j>10){
echo " Variable \$j $j value is greater than 10";
}else{
echo " variable \$j $j is less than 10 but greater than 5";
}
Output is
variable $j 8 is less than 10 but greater than 5
Once all the conditions are False the last line is executed. Variable $j 12 value is greater than 10
$mark=65;
$status=$mark > 50 ? 'Pass':'Fail';
echo $status; # output is Pass
We can receive name from Query string and use the same inside our script.
$name=strlen($_GET['name'])>2 ? $_GET['name'] : 'anonymous';
print($name);
$mark=80;
if($mark >= 50){
echo " You Passed, ";
if ($mark >=80){
echo " You got Distinction also";
} // end of inner if condition
} // end of outer if condition
if (isset($_SESSION['userid']&& !empty($_SESSION['userid']))) {
// Welcome message
}else {
// Ask the user to login
}
What is session variable ?
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.