Results: 132
PHP Variables CODE
Different types of Variables
$name = "George";
$age = 25;
$weight = 75; //kg
$height = 1.85; //m
Variables used in expressions
echo "His name is ".$name."\n";
echo "He is ".$age." years old\n";
echo "He weighs around ".$weight."\n";
echo "he is ".$height."m tall \n";
Variable types CODE
String
$name = "George";
Integer
$weight = 85; //kg
Float
$height = 1.9; //m
Boolean
$male = true;
Array
$colors = ["Red", "Green", "Blue"];
// Instead of storing them in separate variables like this:
$color1 = "Red";
$color2 = "Green";
$color3 = "Blue";
gettype()
returns a type of a given variable
echo gettype($my_name); // string
Rules to create PHP variable CODE
- A variable starts with the
$
sign, followed by the name of the variable - A variable name must start with a letter or the underscore character - A variable name cannot start with a
number
- A variable name can only contain alpha-numeric characters and underscores (
A-z
,
0-9
, and
_
)
// Correct Syntax
$variable_name = "Value";

// Incorrect Syntax
Variable_Name = "Value";
$5variable_name = "Value";
$variable-name = "Value";
set timezone to Asia/Tbilisi (+4)
Sets
timezone
using
php.ini
file
date.timezone = Asia/Tbilisi
Sets
timezone
inside php script file
ini_set('date.timezone', 'Asia/Tbilisi');
Arithmetic operators work with:
integer
and
float
values to perform arithmetical operations. Let's define two variables:
number1
and
number2
and perform these operations
$number1 = 40;
$number2 = 9;
Addition
echo $number1 + $number2 . "\n";
Subtraction
echo $number1 - $number2 . "\n";
Multiplication
echo $number1 * $number2 . "\n";
Division
echo $number1 / $number2 . "\n";
Modulus
echo $number1 % $number2 . "\n";
echo statement CODE
Prints plain text
echo 'plain text'."\n";
Double quotes can parse variables
echo "Double quotes: $text"."\n";
Single quotes can not parse variables
echo 'Single quotes: $text'."\n";
Single quotes as well as double quotes can be concatenated with variables
echo 'Single quotes - '.$text." - Double quotes"."\n";
Text inside Single quotes can include double quotes as part of the text
echo 'The text includes "double" quotes as part of the text'."\n";
Text inside double quotes can include single quotes as part of the text
echo "Jane's surname is Smith"."\n";
echo can be used as a function
echo ('echo as a function')."\n";
echo can print number without quotes
echo 5 . $number;
echo
can take multiple parameters
echo 'one', 'two', 'three', "\n";
We can print multiple lines of text
echo 'Prints text 
    with multiple
lines';
PHP Comments CODE
Single line comment
// $variable = 'Value';
Another single line comment
# $variable = 'Value';
Comment for multiple lines
/*$variable = 'Value';
$second_variable = 'Value 2';
$third_variable = 'Value 3';*/
Inline comment
$number = 5 /* - 5  */ + 5;
Hello world CODE
Prints the text
Hello world
echo "Hello world";
Prints the two words one by one
echo "Hello ";
echo "world";
Prints the variable
$greeting
$greeting = "Hello world";
Echo $greeting;
Concatenates the string to the variable
$greeting
$greeting = "hello world!";
Echo $greeting . " Let's get started!";
Meeting 1
PHP Variables https://learning.applications.ge/note/public/3278 https://www.sololearn.com/learning/1059/1797/3456/1 https://www.w3schools.com/php/php_variables.asp https://www.javatpoint.com/php-variables https://www.tutorialrepublic.com/php-tutorial/php-variables.php Arithmetic Operators https://learning.applications.ge/note/public/3293 https://www.sololearn.com/learning/1059/1803/3469/1 https://www.w3schools.com/php/php_operators.asp Assignment Operators https://learning.applications.ge/note/public/3294 https://www.sololearn.com/learning/1059/1804/3472/1 https://www.w3schools.com/php/php_operators.asp Comparison Operators https://learning.applications.ge/note/public/3295 https://www.sololearn.com/learning/1059/1805/3503/1 https://www.w3schools.com/php/php_operators.asp Rules to create PHP variable https://learning.applications.ge/note/public/3277 https://www.roseindia.net/tutorial/php/phpbeginners/PHPvariable.html Case Sensitivity https://learning.applications.ge/note/public/3283 https://tutorialsclass.com/faq/is-php-a-case-sensitive-language/ PHP Comments https://learning.applications.ge/note/public/3279 https://www.sololearn.com/learning/1059/1795/3453/1 https://www.w3schools.com/php/php_comments.asp https://www.javatpoint.com/php-comments https://www.phptutorial.net/php-tutorial/php-comments/ echo / print https://learning.applications.ge/note/public/3280 https://www.sololearn.com/learning/1059/1794/3450/1 https://www.w3schools.com/php/php_echo_print.asp https://www.javatpoint.com/php-echo https://www.javatpoint.com/php-print https://www.tutorialrepublic.com/php-tutorial/php-echo-and-print-statements.php Differences between echo and print https://learning.applications.ge/note/public/3281 https://www.javatpoint.com/php-echo-and-print-statements Variable types https://learning.applications.ge/note/public/3282 https://www.sololearn.com/learning/1059/1796/3501/1 https://www.w3schools.com/php/php_datatypes.asp https://www.tutorialspoint.com/php/php_variable_types.htm https://www.javatpoint.com/php-data-types https://www.phptutorial.net/php-tutorial/php-data-types/ https://www.tutorialrepublic.com/php-tutorial/php-data-types.php Array types https://learning.applications.ge/note/public/3286 https://www.sololearn.com/learning/1059/1807/3476/1 https://www.sololearn.com/learning/1059/1808/3504/1 https://www.sololearn.com/learning/1059/1809/3505/1 https://www.w3schools.com/php/php_arrays.asp https://www.tutorialspoint.com/php/php_arrays.htm https://www.phptutorial.net/php-tutorial/php-array/ https://www.phptutorial.net/php-tutorial/php-associative-arrays/ https://www.phptutorial.net/php-tutorial/php-multidimensional-array/ https://www.tutorialrepublic.com/php-tutorial/php-arrays.php String functions https://learning.applications.ge/note/public/3284 https://www.w3schools.com/php/php_string.asp https://www.tutorialrepublic.com/php-tutorial/php-strings.php Math functions https://learning.applications.ge/note/public/3285 https://www.w3schools.com/php/php_math.asp If statement https://learning.applications.ge/note/public/3287 https://www.w3schools.com/php/php_if_else.asp https://www.tutorialspoint.com/php/php_decision_making.htm https://www.phptutorial.net/php-tutorial/php-if/ https://www.tutorialrepublic.com/php-tutorial/php-if-else-statements.php If-else statement https://learning.applications.ge/note/public/3288 https://www.sololearn.com/learning/1059/1823/3515/1 https://www.phptutorial.net/php-tutorial/php-if-else/ Else-if statement https://learning.applications.ge/note/public/3289 https://www.sololearn.com/learning/1059/1824/3517/1 https://www.phptutorial.net/php-tutorial/php-if-elseif/ Logical Operators https://learning.applications.ge/note/public/3305 https://www.sololearn.com/learning/1059/1806/3474/1 https://www.w3schools.com/php/php_operators.asp User defined functions https://learning.applications.ge/note/public/3290 https://www.sololearn.com/learning/1059/1834/3540/1 https://www.sololearn.com/learning/1059/1835/3542/1 https://www.w3schools.com/php/php_functions.asp https://www.tutorialspoint.com/php/php_functions.htm https://www.phptutorial.net/php-tutorial/php-function/ https://www.tutorialrepublic.com/php-tutorial/php-functions.php Loops https://learning.applications.ge/note/public/3291 https://www.sololearn.com/learning/1059/1826/3521/1 https://www.w3schools.com/php/php_looping.asp https://www.tutorialspoint.com/php/php_loop_types.htm https://www.phptutorial.net/php-tutorial/php-for-loop/ https://www.tutorialrepublic.com/php-tutorial/php-loops.php The break statement https://learning.applications.ge/note/public/3316 https://www.w3schools.com/php/php_looping_break.asp The continue statement https://learning.applications.ge/note/public/3317 https://www.sololearn.com/learning/1059/1831/3531/1 https://www.w3schools.com/php/php_looping_break.asp Main resources to learn PHP basics: https://www.php.net/ (official doc) https://www.sololearn.com/learning/1059 https://www.w3schools.com/php/ https://www.phptutorial.net/ https://www.tutorialrepublic.com/php-tutorial/ https://www.tutorialspoint.com/php/ https://www.javatpoint.com/php-tutorial PHP online editors: https://onlinephp.io/ https://www.writephponline.com/ https://www.mycompiler.io/new/php
PHP else-if statement CODE
The code will output "Have a nice weekend!" if the current day is Friday, and "Have a nice Sunday!" if the current day is Sunday, otherwise it will output "Have a nice day!"
$d = date("D");
if($d == "Fri"){
    echo "Have a nice weekend!";
} elseif($d == "Sun"){
    echo "Have a nice Sunday!";
} else{
    echo "Have a nice day!";
}
echo "\n";
Outputs
Have a good morning!
if the current time is less than 10, and
Have a good day!
if the current time is less than 20. Otherwise it will output
Have a good night!
$t = date("H");
if ($t < "10") {
	echo "Have a good morning!";
} elseif ($t < "20") {
	echo "Have a good day!";
} else {
	echo "Have a good night!";
}
Prints
Adult
If
$age
is more than
18
, and
Teenager
if the variable is less than 12. Otherwise it prints
Child
$age = 20;
if ($age > 18) {
    echo 'Adult';
} else if ($age > 12) {
    echo 'Teenager';
} else {
    echo 'Child';
}
Results: 132