if (0) { // false same as empty, true same as 1
echo "true";
} else {
echo "false";
}
// therefore condition returns false :)
define(name, value, case-insensitive)
Parameters:
name: Specifies the name of the constant;
value: Specifies the value of the constant;
case-insensitive: Specifies whether the constant name should be case-insensitive. Default is false;
The example below creates a constant with a case-sensitive name:
<?php
define("georgian_player", "Kvicha Kvaratskhelia");
echo georgian_player;
// Outputs "Kvicha Kvaratskhelia"
?>
The example below creates a constant with a case-insensitive name:
<?php
define("georgian_player", "Kvicha Kvaratskhelia", true);
echo Georgian_Player;
// Outputs "Kvicha Kvaratskhelia"
?>
No dollar sign ($) is necessary before the constant name.$x = 10;
if ($x > (2+4)) {
echo "Condition is True !\n";
} else {
echo "Condition is False !\n";
} // outputs: Condition is True !
if ($x < (2+4)) {
echo "Condition is True !\n";
} else {
echo "Condition is False !\n";
} // outputs: Condition is False !
$my_age = 19;
if ($my_age >= 18 ) {
echo "I am adult!";
} else {
echo "I am child!";
} // outputs: I am adult!
<?php
function myTest() {
static $x = 0;
echo $x;
$x++;
}
myTest(); // output is 1
myTest(); // output is 2
myTest(); // output is 3
?>
Then, each time the function is called, that variable will still have the information it contained from the last time the function was called.
Note: The variable is still local to the function.$name = "Levani";
if ( $name == "Levani") {
echo "Condition is True !\n";
}
// "l" A full textual representation of the day of the week
if (date("l") == "Monday") {
echo "Let's start coding !\n";
}
$x = 10;
$y = 5;
if ($x > $y) {
echo "10 > 5\n";
}
if ($x < 2) {
// conditions is false
}
<?php
$x = 70;
$y = 7;
function myNum {
$GLOBALS['y'] = $GLOBALS['x'] + $GLOBALS['y'];
}
myNum();
echo $y; // output is 77
?>
<?php
$x = 70;
$y = 7;
function myNum {
global $x, $y;
$y = $x + $y;
}
myNum();
echo $y; // output is 77
?>