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