Web Technologies

echo & print and Constant in PHP

echo is fast, can take multiple arguments & can print value of variable in double quotes

// Print can't take multiple arguments & always return 1 while echo is not return anything and echo is fast
echo "How are you? ", "fine?";

// In double quote we can print php variable
echo "boy has $x inr";

PHP constants has global scope.

They can defined with const keyword or by define() method. once declare the constants, it is not allowed to change the value.

define('PI', 999);
echo PI;

const myname = 'DILIP';
echo myname;

const vs. define()

  • const & define both are always case-sensitive
const myname = 'DILIP';
const MYNAME = 'DEEP';
echo MYNAME; //DEEP
echo myname; // DILIP
  • const cannot be created inside another block scope, like inside a function or inside an if statement.
  • define can be created inside another block scope.