"Welcome to our PHP 101 blog, where we demystify the world of web development. "

Friday, January 19, 2024

Short Hand If


Short Hand If

Short Hand If

To write shorter code, you can write if statements on one line.

One-line if statement:

Example:

$a = 5;

if ($a < 10) $b = "Hello";

echo $b

Output:


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:

example:

$a = 13;

$b = $a < 10 ? "Hello" : "Good Bye";

echo $b;

Output:

No comments:

Post a Comment

Pages

SoraTemplates

Best Free and Premium Blogger Templates Provider.

Buy This Template