NOVINKA: Najžiadanejšie rekvalifikačné kurzy teraz s 50% zľavou + kurz AI ZADARMO. Nečakaj, táto ponuka dlho nevydrží! Zisti viac:

PHP - empty

Trieda

Koreň \ Bez triedy

Metóda - empty

(PHP 4, PHP 5, PHP 7)

The function determines whether a variable is considered to be "empty". Variables are empty if they don't exist or the're false (using the standard comparison so also including values like 0, "" etc.). The function doesn't produce any error in case the variable doesn't exists, just returns true instead.

If we pass an inaccessible object property to the function, the __isset() magic method of the given object will be invoked.

Note: isset() is not a function but a language construct. Therefore, it can't be e.g. stored in a variable.

Procedurálne

  • function empty (mixed $var) : bool

Parametre

NázovDátový typPredvolená hodnotaPopis
$varmixed

The variable being checked.

Mávratovej hodnoty

Vracia: bool

The function returns true in cases the variable is considered to be empty, returns false otherwise.

The variable is considered to be "empty" in these cases:

$var = 0; // zero as integer
$var = 0.0; // zero as float
$var = "0"; /

Príklady

<?php
echo empty(0) ? "0 as a number IS considered to be empty. <br>" : "0 as a number IS NOT considered to be empty. <br>";
echo empty(7) ? "Number 7 IS considered to be empty. <br>" : "Number 7 IS NOT considered to be empty. <br>";
echo empty(0.0) ? "0.0 as a float IS considered to be empty. <br>" : "0.0 as a float IS NOT considered to be empty. <br>";
echo empty(0.3) ? "0.3 as a float IS considered to be empty. <br>" : "0.3 as a float IS NOT considered to be empty. <br>";
echo empty("0") ? "0 as a string IS considered to be empty. <br>" : "0 as a string IS NOT considered to be empty. <br>";
echo empty("17.5") ? "17.5 as a string IS considered to be empty. <br>" : "17.5 as a string IS NOT considered to be empty. <br>";
echo empty("Porsche") ? "Porsche as a string IS considered to be empty. <br>" : "Porsche as a string IS NOT considered to be empty. <br>";
echo empty("") ? "An empty string IS considered to be empty. <br>" : "An empty string IS NOT considered to be empty. <br>";
echo empty(NULL) ? "The value NULL IS considered to be empty. <br>" : "The value NULL IS NOT considered to be empty. <br>";
echo empty(false) ? "The value false IS considered to be empty. <br>" : "The value false IS NOT considered to be empty. <br>";
echo empty(true) ? "The value true IS considered to be empty. <br>" : "The value true IS NOT considered to be empty. <br>";

Súvisiace manuály

      • function array_key_exists (mixed $key, array $array) : bool
      • function count (mixed $array_or_countable, int $mode = COUNT_NORMAL) : int
      • function isset (mixed $var, mixed $...) : bool
      • function strlen (string $string) : int
      Aktivity