PHP Shorthand if Statements
Posted 2024-05-17 07:47:03
0
2K
Short Hand If
To write shorter code, you can write if
statements on one line.
ExampleGet your own PHP Server
One-line if
statement:
$a = 5;
if ($a < 10) $b = "Hello";
echo $b
Try it Yourself »Short Hand If...Else
if
...else
statements can also be written in one line, but the syntax is a bit different.
Example
One-line if
...else
statement:
$a = 13;
$b = $a < 10 ? "Hello" : "Good Bye";
echo $b;
Try it Yourself »This technique is known as Ternary Operators, or Conditional Expressions.
Cerca
Categorie
- Art
- Causes
- Crafts
- Dance
- Drinks
- Film
- Fitness
- Food
- Giochi
- Gardening
- Health
- Home
- Literature
- Music
- Networking
- Altre informazioni
- Party
- Religion
- Shopping
- Sports
- Theater
- Wellness
Leggi tutto
PHP if Statements
Conditional statements are used to perform different actions based on different conditions....
PHP Constants
Constants are like variables, except that once they are defined they cannot be changed or...
PHP Strings
A string is a sequence of characters, like "Hello world!".
Strings
Strings in PHP are...
PHP Casting
Sometimes you need to change a variable from one data type into another, and sometimes you want a...
PHP if Operators
Comparison Operators
If statements usually contain conditions that compare two values....