An error has occurred:

Error at 2023-03-29 03:28:11: Query:
URL: /blog/104/sentencias-cortas-en-php-tiny-conditions-if-else/en
E: Unknown column 'thumb' in 'field list'

Severity: Fatal

An error has occurred:

Error at 2023-03-29 03:28:11: Query:
URL: /blog/104/sentencias-cortas-en-php-tiny-conditions-if-else/en
E: Unknown column 'thumb' in 'field list'

Severity: Fatal

Short statements in PHP / Tiny conditions if - else

  1. Inicio
  2. /
  3. Blog
  4. /
  5. Sentencias cortas en PHP / Tiny conditions if - else

Short statements in PHP / Tiny conditions if - else

How to replace long statements or conditions in PHP?

Léelo en Español / 2 mins.
sentencias cortas en php tiny conditions if else


In software development, the creation of sentences is something daily. Next you will discover some methods that will allow you to do everything in one line, benefiting you in time and in debugging your code:

Basic declaration of TRUE / FALSE

$ is_admin = ($ user ['permissions'] == 'admin')? true: false;


Welcome condition

echo 'Welcome'. ($ user ['is_logged_in']? $ user ['name']: 'Guest'). '!';


Item condition

echo 'The shopping cart contains'. $ num_items.' item '. ($ num_items! = 1?' s': '');


Safety condition

echo '<base href =" http'. ($ PAGE_IS_SECURE? 's': ''). ': //mydomain.com "/>';


Subconditions

echo 'Your score is:'. ($ score> 10? ($ age> 10? 'Average': 'Exceptional'): ($ age> 10? 'Horrible': 'Average'));


A condition for redirection

header ('Location:'. ($ valid_login? '/members/index.php': 'login.php? errors = 1')); exit ();







VPS CHILE Servidor virtual para tus aplicaciones con IP dedicada. Discos de alta velocidad. La mejor performance en Chile.
HOSTING CHILE Hosting solución para proyectos web. Discos ssd de alta velocidad. Servicio ideal para todo tipo de proyecto.
VPN CHILE Solución para todo usuario. Navegar de forma segura y anónima en internet.

Lee también



Cargando...