PHP Shorthand if Statements

0
4كيلو بايت

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.

البحث
الأقسام
إقرأ المزيد
أخرى
PHP Shorthand if Statements
Short Hand If To write shorter code, you can write if statements on one line....
بواسطة PHP Tutorial 2024-05-17 07:47:03 0 4كيلو بايت
أخرى
PHP Indexed Arrays
PHP Indexed Arrays In indexed arrays each item has an index number. By default, the first item...
بواسطة PHP Tutorial 2024-05-17 08:00:38 0 5كيلو بايت
أخرى
PHP Operators
PHP Operators Operators are used to perform operations on variables and values. PHP divides the...
بواسطة PHP Tutorial 2024-05-17 07:41:39 0 9كيلو بايت
أخرى
PHP $GLOBALS
$GLOBALS is an array that contains all global variables. Global Variables Global...
بواسطة PHP Tutorial 2024-05-17 08:08:27 0 7كيلو بايت
أخرى
PHP Add Array Items
Add Array Item To add items to an existing array, you can use the bracket [] syntax....
بواسطة PHP Tutorial 2024-05-17 08:06:05 0 7كيلو بايت
Sociallez https://sociallez.com