PHP Shorthand if Statements

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.

Site içinde arama yapın
Kategoriler
Read More
Other
PHP if Operators
Comparison Operators If statements usually contain conditions that compare two values....
By PHP Tutorial 2024-05-17 07:45:46 0 4K
Other
PHP Math
PHP has a set of math functions that allows you to perform mathematical tasks on numbers. PHP...
By PHP Tutorial 2024-05-17 07:39:09 0 6K
Other
PHP Break
The break statement can be used to jump out of different kind of loops. Break in For...
By PHP Tutorial 2024-05-17 07:50:37 0 5K
Other
تطورات التعلم الآلي وتأثيرها على مستقبل العمل
مقدمة: في ظل التطورات السريعة للتكنولوجيا والابتكار، أصبح التعلم الآلي...
By MOHAMED ATTALLAH 2024-05-14 13:56:58 0 7K
Other
PHP Nested if Statement
Nested If You can have if statements inside if statements, this is...
By PHP Tutorial 2024-05-17 07:47:26 0 4K
Sociallez https://sociallez.com