$სწავლა_გვინდა = true;
$ვაბარებთ_უნივერსიტეტში = true;
$სწავლა_ძვირია = true;
$მუშაობა_გვინდა = false;
if ($სწავლა_გვინდა) {
if ($ვაბარებთ_უნივერსიტეტში) {
if ($სწავლა_ძვირია) {
echo "\nუნივერსიტეტი ძვირია, ვიწყებთ სწავლას applications.ge-ს კურსზე!";
} else {
echo "\nვსწავლობთ უნივერსიტეტში!";
}
} else {
echo "\nვიწყებთ სწავლას applications.ge-ს კურსზე!";
}
} elseif ($მუშაობა_გვინდა) {
echo "\nვმუშაობთ";
} else {
echo "\nდროს ნუ კარგავ!";
}
static
keyword when you first declare the variable:
For instance:
// function with static variable
function get_num1() {
static $number1 = 0;
echo $number1++." ";
}
get_num1();
get_num1();
get_num1(); echo "\n";
// outputs: 0 1 2
// function without static variable
function get_num2() {
$number2 = 0;
echo $number2++." ";
}
get_num2();
get_num2();
get_num2();
// outputs: 0 0 0
global scope
.
• A variable declared within a function has a local scope
, and can only be accessed within that function.
For instance:
// global scope
$number = 10;
function print_num() {
echo "the number is: $number ";
}
print_num(); // outputs: Undefined variable $number
// the $number variable has a global scope, and is not accessible within the print_num() function
function task() {
$name = "Mads"; // local scope
echo "Variable name inside function is: $name";
// outputs: Variable name inside function is: Mads
}
task();
// using $name outside the function will generate an error
echo "Variable name outside function is: $name";
// Undefined variable $name
`
Formats can be:
echo "Today is ". date("Y/m/d") . "\n";
echo "Today is ". date("d/m/Y"). "\n";
echo "Today is ". date("D/M/Y"). "\n";
echo "Today is ". date("d/M/Y"). "\n";
echo "Today is ". date("d.m.Y"). "\n";
echo "Today is ". date("d-m-Y"). "\n";
echo "Today is ". date("l"). "\n";
`
`
Output:
Today is 2022/10/22
Today is 22/10/2022
Today is Sat/Oct/2022
Today is 22/Oct/2022
Today is 22.10.2022
Today is 22-10-2022
Today is Saturday
``
$items = array("me", "you", "he");
array_push($items, "she", "we");
print_r($items);
`$array = [1, 2, "name"=>"Three", 4];
print_r($array);
ResultArray
(
[0] => 1
[1] => 2
[name] => Three
[2] => 4
)
If we set higher index manually, it will continue adding 1 to the max index$array = [1, 2, 7=>"Three", 4];
print_r($array);
ResultArray
(
[0] => 1
[1] => 2
[7] => Three
[8] => 4
)
If we set higher index manually, it will continue adding 1 to the index$array = [1, 2, 7=>"Three", 4=>"forth", 25];
print_r($array);
ResultArray
(
[0] => 1
[1] => 2
[7] => Three
[4] => forth
[8] => 25
)
Only integer and string values are allowed as array keys
$array = [
1 => "a",
"1" => "b",
"-1" => "-b",
'1.5' => "c",
true => "d",
];
print_r($array);
ResultArray
(
[1] => d
[-1] => -b
[1.5] => c
)
==
and ===
operator in PHP ?
In PHP
== is equal operator and returns TRUE
if $a is equal to $b after type juggling and === is Identical operator and return TRUE
if $a is equal to $b, and they are of the same data type
$a=true ;
$b=1;
// Below condition returns true and prints a and b are equal
if($a==$b){
echo "a and b are equal";
}
else{
echo "a and b are not equal";
}
//Below condition returns false and prints a and b are not equal because $a and $b are of different data types.
if($a===$b){
echo "a and b are equal";
}
else{
echo "a and b are not equal";
}