Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php const

<?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'));
?>
Comment

define constant in php

<?php
	define("emp_name","Kumar D");
	echo constant("emp_name");
	//or 
	echo emp_name;
?>
Comment

php constant

<?php
define("PI",3.14);
echo PI;
echo constant("PI");
?>
Comment

PHP constants

//define(name,value);

define("PI",3.1419); 
Comment

php constant name with variable

echo constant($constant_name);
Comment

class constants in php

<?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."
";
?>
Comment

PHP constant

class Human {
  const TYPE_MALE = 'm';
  const TYPE_FEMALE = 'f';
  const TYPE_UNKNOWN = 'u'; // When user didn't select his gender
  
  .............
}
Comment

how to create constant in php

<?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
?>
Comment

Constants In PHP

<?php
define("A", 100);
define("B", 200);
echo A;
echo "<br>";
echo B;
?>
Comment

PHP Constants

<?php
define("GREETING", "Welcome to my profile");
echo GREETING;
?>
Comment

php variable constant

if (...) {
     const FOO = 'BAR';    // Invalid
 }
 // but
 if (...) {
     define('FOO', 'BAR'); // Valid
 }
Comment

PREVIOUS NEXT
Code Example
Php :: php override trait method and call it 
Php :: laravel check if object is empty 
Php :: php if mobile 
Php :: replace 0 in number to add 234 php 
Php :: socialite laravel 7 
Php :: php remove html tag 
Php :: php call class dynamically 
Php :: php get looping month 
Php :: array collapse laravel 
Php :: Fibonacci Series Program. in php 
Php :: generate laravel event 
Php :: how to remove duplicate values from an array in php 
Php :: php timezone 
Php :: laravel composite unique key 
Php :: wp tax_query in 
Php :: laravel select only some columns relationship 
Php :: migration laravel 
Php :: composer update php mbstring.so missing 
Php :: laravel 8 try catch 
Php :: php parse file 
Php :: php group array by value and count 
Php :: laravel validation unique email except self 
Php :: laravel migration table column nullable 
Php :: Class "AppHttpControllersAdminController" not found in laravel 8 
Php :: timestamp php 
Php :: update laravel .env variables dynamically 
Php :: laravel required_if 
Php :: php read mysql 
Php :: login form in php 
Php :: print array in php 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =