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 do while Loop
The do...while loop - Loops through a block of code once, and then repeats the loop as...
Por PHP Tutorial 2024-05-17 07:49:22 0 5KB
Outro
PHP Syntax
A PHP script is executed on the server, and the plain HTML result is sent back to the browser....
Por PHP Tutorial 2024-05-17 07:10:53 0 9KB
Outro
PHP Array Functions
PHP Array Functions PHP has a set of built-in functions that you can use on arrays....
Por PHP Tutorial 2024-05-17 08:07:42 1 8KB
Outro
PHP Nested if Statement
Nested If You can have if statements inside if statements, this is...
Por PHP Tutorial 2024-05-17 07:47:26 0 4KB
Outro
PHP - $_SERVER
$_SERVER $_SERVER is a PHP super global variable which holds information about headers,...
Por PHP Tutorial 2024-05-17 08:08:50 0 8KB
Sociallez https://sociallez.com