PHP Conditinal Statements
Learn PHP conditional statement to perform different action based on the condition that you have set.
3 years ago
118
Code Example
<?php
// if statement
$hungry = true;
if ($hungry) {
echo "Let's grab some food to eat";
}
// if..else Statement
$energetic = false;
if ($energetic) {
echo "Get some rest";
} else {
echo "Let's go for a trip";
}
// if..elseif..else Statement
$name = "John Doe";
if ($name == "John Doe") {
echo "Hey, what's up bro!";
} else if ($name == "Jane Doe") {
echo "Hey, what's up sis!";
} else {
echo "Hey there!"
}
// Switch statement
$cost = 100;
switch($cost) {
case 0:
echo "It's free";
break;
case 50:
echo "It's 50 USD";
break;
case 100:
echo "It's 100 USD";
break;
default:
echo "I can't guess it!"
}
PHP Tags
PHP Variables
PHP Data Types
PHP Comments
PHP Loops
PHP Functions
PHP Arrays
PHP Conditinal Statements
Code Snippets
Collection of Laravel, AlpineJS, VueJS, Tailwind CSS, Flutter snippets and more. New snippets added every day.
View Snippets
Code Components
Collection of Tailwind CSS components for everyone to use. Browse all of the components that's right for your
web projects
View Components