Blog de programación, errores, soluciones

Chose Language:
Author: Admin/Publisher |finished | checked

PHP isset function

PHP isset function check if a variable is defined and not null, so, if the variable is not defined it will return false, if the variable is null it will return false. If the variable is defined, it will return true.

Description / Descripción
isset(mixed $var, mixed ...$vars): bool
Sintaxis / Sintax
isset($var)

Return:

true – The variable is defined and its value is not null.

false – The variable is null or not defined.

Check if multiple variables are defined.

Keep in mind that we can check one or several variables at once, for example:

chequeando múltiples variables
isset($a,$b,$c)

If checking multiple variables, all variables must be defined and not null in order to return true.

Check if an index exists in an array.

$miArray = array('Roberto', 'Juan', 'Marta');
if (isset($miArray[0])) {
  echo "El índice 0 es".$miArray[0];
}

Many times, isset is used to prevent errors of type “Undefined variable” or “Undefined index” that may occur when trying to access a variable that has not been defined or does not exist.

Category: en-php
Something wrong? If you found an error or mistake in the content you can contact me on Twitter | @luisg2249_luis.
Last 4 post in same category