PHP Shorthand if Statements

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.

Pesquisar
Categorias
Leia mais
Outro
PHP Constants
Constants are like variables, except that once they are defined they cannot be changed or...
Por PHP Tutorial 2024-05-17 07:39:53 0 8KB
Outro
PHP Introduction
PHP code is executed on the server. What You Should Already Know Before you continue you...
Por PHP Tutorial 2024-05-17 07:08:40 0 4KB
Outro
الثورة البلوكتشين وتحولاتها في الصناعات المختلفة
مقدمة: شهدت تقنية البلوكتشين ثورة هائلة في السنوات الأخيرة، حيث أصبحت لديها القدرة على تغيير...
Por MOHAMED ATTALLAH 2024-05-14 14:03:03 0 7KB
Outro
PHP Continue
The continue statement can be used to jump out of the current iteration of a loop, and...
Por PHP Tutorial 2024-05-17 07:52:32 0 4KB
Outro
PHP Installation
What Do I Need? To start using PHP, you can: Find a web host with PHP and MySQL support...
Por PHP Tutorial 2024-05-17 07:09:40 0 5KB
Sociallez https://sociallez.com