PHP Shorthand if Statements
Posted 2024-05-17 07:47:03
0
4K
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.
Search
Categories
- Art
- Causes
- Crafts
- Dance
- Drinks
- Film
- Fitness
- Food
- Games
- Gardening
- Health
- Home
- Literature
- Music
- Networking
- Other
- Party
- Religion
- Shopping
- Sports
- Theater
- Wellness
Read More
PHP while Loop
The while loop - Loops through a block of code as long as the specified condition is...
PHP Math
PHP has a set of math functions that allows you to perform mathematical tasks on numbers.
PHP...
PHP Introduction
PHP code is executed on the server.
What You Should Already Know
Before you continue you...
PHP Multidimensional Arrays
In the previous pages, we have described arrays that are a single list of key/value pairs....
PHP Associative Arrays
PHP Associative Arrays
Associative arrays are arrays that use named keys that you assign to...