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 Access Arrays
Access Array Item To access an array item, you can refer to the index number for indexed arrays,...
От PHP Tutorial 2024-05-17 08:02:32 0 8Кб
Другое
PHP Comments
Comments in PHP A comment in PHP code is a line that is not executed as a part of the program....
От PHP Tutorial 2024-05-17 07:14:49 0 6Кб
Другое
PHP Constants
Constants are like variables, except that once they are defined they cannot be changed or...
От PHP Tutorial 2024-05-17 07:39:53 0 8Кб
Другое
PHP Numbers
In this chapter we will look in depth into Integers, Floats, and Number Strings. PHP Numbers...
От PHP Tutorial 2024-05-17 07:37:05 0 6Кб
Другое
PHP Array Functions
PHP Array Functions PHP has a set of built-in functions that you can use on arrays....
От PHP Tutorial 2024-05-17 08:07:42 1 8Кб
Sociallez https://sociallez.com