<?php
define('CONSTANT', 'Hello world !');
const CONSTANT = 'Hello world !';
const NEW_CONSTANT = CONSTANT.' And beyond...';
const ANIMALS = array('dog', 'cat', 'ant');
define('ANIMALS', array('dog', 'cat', 'ant'));
?>
<?php
define("emp_name","Kumar D");
echo constant("emp_name");
//or
echo emp_name;
?>
<?php
define("PI",3.14);
echo PI;
echo constant("PI");
?>
//define(name,value);
define("PI",3.1419);
echo constant($constant_name);
<?php
class MyClass
{
const CONSTANT = 'constant value';
function showConstant() {
echo self::CONSTANT . "
";
}
}
echo MyClass::CONSTANT . "
";
$classname = "MyClass";
echo $classname::CONSTANT . "
";
$class = new MyClass();
$class->showConstant();
echo $class::CONSTANT."
";
?>
class Human {
const TYPE_MALE = 'm';
const TYPE_FEMALE = 'f';
const TYPE_UNKNOWN = 'u'; // When user didn't select his gender
.............
}
<?php
#Syntax to define a constant is Define("Name","Value","Case-insensitive")
#For case-insensitive, sensitive is default
define("Tau","6.28318530718","true");
echo tAU;
#Fun fact: Tau = Pi x 2
?>
<?php
define("A", 100);
define("B", 200);
echo A;
echo "<br>";
echo B;
?>
<?php
define("GREETING", "Welcome to my profile");
echo GREETING;
?>
if (...) {
const FOO = 'BAR'; // Invalid
}
// but
if (...) {
define('FOO', 'BAR'); // Valid
}
Code Example |
---|
Php :: laravel mail cc |
Php :: Laravel run seed table |
Php :: spaceship operator |
Php :: php call method from another class |
Php :: find substring php |
Php :: how to get array key in php |
Php :: -store() laravel change name |
Php :: wordpress query get results |
Php :: php localhost:8000 |
Php :: append in php |
Php :: Best Security tools for php |
Php :: laravel how can I use the same foreign key twice in a single table |
Php :: php compare dates |
Php :: php inline if condition date time |
Php :: php ksort |
Php :: laravel validation custom message example |
Php :: laravel collection get |
Php :: php concatenation with a space |
Php :: datatables |
Php :: laravel_login |
Php :: laravel eloquent relationship |
Php :: laravel relation with limit |
Php :: how to create a php website |
Php :: PHP - json_encode() |
Php :: edd login page wordpress |
Php :: sqlstate[22023]: invalid parameter value: |
Php :: laravel event listener |
Php :: laravel email validation |
Php :: rest api php |
Php :: php rtrim |