PHP Shorthand if Statements
Posté 2024-05-17 07:47:03
0
4KB
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.
Rechercher
Catégories
- Art
- Causes
- Crafts
- Dance
- Drinks
- Film
- Fitness
- Food
- Jeux
- Gardening
- Health
- Domicile
- Literature
- Music
- Networking
- Autre
- Party
- Religion
- Shopping
- Sports
- Theater
- Wellness
Lire la suite
PHP - Slicing Strings
Slicing
You can return a range of characters by using the substr() function.
Specify...
PHP Strings
A string is a sequence of characters, like "Hello world!".
Strings
Strings in PHP are...
PHP Array Functions
PHP Array Functions
PHP has a set of built-in functions that you can use on arrays....
PHP Global Variables - Superglobals
Superglobals were introduced in PHP 4.1.0, and are built-in variables that are always available...
PHP Functions
The real power of PHP comes from its functions.
PHP has more than 1000 built-in functions, and...