AgerNic.com/ro
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL
Tutorial

Tutorial PHP» Constante PHP

Constanțele PHP sunt ca variabile, cu excepția faptului că, odată definite, nu pot fi modificate sau nedefinite.
O constantă este un identificator (nume) pentru o valoare simplă. Valoarea nu poate fi modificată în timpul scriptului.

Un nume constant valabil începe cu o literă sau subliniere (nu există semn $ înainte de constanta).

Notă: Spre deosebire de variabile, constantele sunt automat globale pe întregul script.
Creați o constantă PHP
Pentru a crea o constantă, utilizați funcția define() .

Sintaxă
define(name, value, case-insensitive)


parametri:

nume: Specifică numele constantei
valoare: specifică valoarea constantei
case-insensitive: Specifică dacă constanta trebuie să fie sensibil la litere mari și mici. Implicit este fals.

Exemplu
Creați o constantă cu case-sensitive name:

<?php
define ("GREETING", "Welcome to AgerNic.com/ro/!");
echo GREETING;
?>

Exemplu
Creați o constantă cu case-insensitive:

<?php
define("GREETING", "Welcome to AgerNic.com/ro/!", true);
echo greeting;
?>
PHP Arrayuri constante
În PHP7, puteți crea o constantă Array folosind funcția define().
<?php
define("masini", ["Audi", "Dacia", "Toyota"]);
echo masini[1];
?>
Constante sunt globale.
Constanțele sunt automat globale și pot fi utilizate pe întregul script.
<?php
define ("GREETING", "Welcome to AgerNic.com/ro/!");
function phpTest() {echo GREETING;
}
phpTest();
?>
Tags: PHP Constante, exemplu de cod PHP utilizand Constante, script

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


analytics piwika