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 - define

Trieda

Koreň \ Bez triedy

Metóda - define

(PHP 4, PHP 5, PHP 7)

The define() function is used to define a named constant during runtime.

Note: We can use the defined() function to determine whether a constant is defined.

Procedurálne

  • function define (string $name, mixed $value, bool $case_insensitive = false) : bool

Parametre

NázovDátový typPredvolená hodnotaPopis
$namestring

The name of the constant for usage in code.

$valuemixed

The value of the constant. In PHP 5, the value must be scalar (integer, float, string, boolean, and null). Since PHP 7, it's also possible to use arrays. It's not recommended to use constants of the resource type.

$case_insensitivebool false

If the value is true, the name of the constant will be case-insensitive.

Note: Case-insensitive constants are internally stored as lower-case.

Mávratovej hodnoty

Vracia: bool

Returns true if the named constant has been defined successfully, false otherwise.

Príklady

<?php
define('CONST_NUMBER', 1);
define('CONST_TEXT', 'Hello World!', true);

echo CONST_NUMBER; // prints 1
echo '<br>';
echo cOnST_NUmBER; // prints "cOnST_NUmBER" and a notice

echo '<br>';

echo CONST_TEXT; // prints "Hello World!"
echo '<br>';
echo cOnst_TEXT; // prints "Hello World!"

Súvisiace manuály

      • function constant (string $name) : mixed
      • function defined (string $name) : bool
      Aktivity