`<!DOCTYPE html>
<html>
<body>
<?php
ECHO "Hello World!<br>";
echo "Hello World!<br>";
EcHo "Hello World!<br>";
?>
</body>
</html>
Note: However; all variable names are case-sensitive!<?php
$name='GURAM';//Global variable
function local_var() {
$name='guram'; //local variable
echo 'Local variable: '.$name ."\n";
}
local_var();
echo 'Global variable: '.$name;
?>
"static"
Normally, when a function is completed/executed, all of its variables are deleted. However, sometimes we want a local variable NOT to be deleted. We need it for a further job. To do this, use the static keyword when you first declare the variable:
<?php
function myTest() {
static $x = 0;
echo $x;
$x++;
}
myTest();
myTest();
myTest();
?>
<!DOCTYPE html>
<html>
<body>
<?php
$students_inf = array(
array(
"Name" => 'Luka',
"Age" => 21,
"E-mail" => 'Luka.N111@gmail.com',
"Status" => 'Registered'
),
array(
"Name" => 'Nini',
"Age" => 20,
"E-mail" => 'Nini.K312@gmail.com',
"Status" => 'Unregistered'
),
array(
"Name" => 'Giorgi',
"Age" => 22,
"E-mail" => 'Giorgi.ES8@gmail.com',
"Status" => "Registered"
)
);
//You can get students information with echo and var_dump.
var_dump(json_encode($students_inf));
echo str_repeat("<br />",5);
echo $students_inf[0]['Name']. "<br />";
echo $students_inf[0]['Age']. "<br />";
echo $students_inf[1]['Status']. "<br />";
echo $students_inf[2]['E-mail']. "<br />";
?>
</body>
</html>
<?php declare(strict_types=1); // strict requirement
function addNumbers(int $a, int $b) {
return $a + $b;
}
echo addNumbers(5, "5 days");
// since strict is enabled and "5 days" is not an integer, an error will be thrown
?>
const a = 10 + '20'; // the sum of integer and string values
const b = '20' + '20'; // the sum of two string values
console.log(a, b); // returns "1020" , "2020"
console.log(typeof(a, b)); // both are strings
$a = 10 + '20'; // The sum of an integer and a string
$b = '1020' + '20'; // The sum two strings
echo $a, "\n ", $b, "<br>"; // returns 30, 1040
echo var_dump($a, $b); // both are integers (int+str) (str+str)
/* When you try to perform math operations with strings in PHP, they are cast to approprite type. In this case to int. But you can cast integer back to string in the below example */
$integer = 10;
$stringIncrement = '20';
$result = $integer + $stringIncrement;
$result = (string) $result;
var_dump($result);
// make the while loop example
$i = 1;
while ($i < 5) {
echo "the result is $i", "\n";
$i++;
}
// please note, If the condition never becomes false, the statement will continue to execute indefinitely.
// make the do...while loop
$i = 1;
do {
echo "hello world";
}
while ($i < 0);
// is that case will return the result?
/* Note that in a do while loop, the condition is tested AFTER executing the statements within the loop. This means that the do while loop would execute its statements AT LEAST ONCE, EVEN IF THE CONDITION IS FALSE the first time */
// Therefore it returns "hello world" only one time