Tools
PHP Syntax Cheatsheet [Part 1]
2025-12-28
0 views
admin
Table of Content ## Syntax ## Comments ## Variables ## Variable variables ## Constant ## Run-time constant ## Compile-time constant ## String ## Integer ## Boolean ## Index-based array ## Key-based array ## Array language construct ## Multi-dimensional arrays ## Echo and Print ## Casting ## Operators ## Arithmetic operators ## + Summation ## - Subtraction ## * Multiplication ## / Division ## ** Exponentiation ## % Modulo ## Comparison operators ## == equal and !=/<> not equal ## === identical and !== not identical ## < less than and <= less than or equal ## > greater than and >= greater than or equal ## <=> Spaceship operator ## Conditions ## If-else and elseif ## Switch case ## For loop ## While loop ## Do while loop ## Foreach loop ## Functions ## NodeJS Essentials | Free E-Book ## Adnan Babakan (he/him) ・ Sep 11 '20 Hey there DEV.to community! Here I am compiling a list of PHP syntax cheatsheet for you all. As for why I am writing this post, PHP was my first programming language, and I still feel like I am in love with it, and it deserves more attention. Thus, trying to spread PHP knowledge for those learning it for the first time or trying to get back to it. In this part I will go through basic PHP syntax and in the next part I will discuss the OOP aspect much more in detail. PHP files are named with .php extension and start with <?php or <? and end with ?>. It is good to not that ending tag is not mandatory if you whole file consists of PHP and no HTML afterwards. As for every programming language you need comments to describe your code. PHP provides multiple ways to comment. Using // and #, you may create a single-line comment. And by putting you comment between /* and */ you can create a multi-line comment. Variables in PHP are defined using $ followed by their name. A variable in PHP isn't typed and can hold any value that PHP offers. A variables value can be changed later on. It is good to know that PHP statements require a semicolon at the end, and it is not optional. While it is against the convention, since variables are defined using $, it is possible to define a variable's name using another variable. I am not encouraging using such an approach, but it is possible, so mentioning it here is an honourable mention. A constant is almost like a variable but its value can only be declared once and later on it cannot be changed. By convention constant names are defined in UPPER_SNAKE_CASE. A runtime constant can be defined using the define() function. A compile-time constant can be defined using the const keyword. PHP is a dynamically-typed language, which means you don't need to declare every type you use, yet it is essential to know what you are passing around as values so you can control how it affects your program. A string is a series of characters, such as a name or a full sentence. A PHP string can be defined between quotes ' and double-quotes ". The difference between a single quote and a double quote is simple. Inside a single-quote, wrap everything is considered literal and will remain as is. But inside a double-quote, variables are evaluated, and their values are placed in the string. For best practices, it is good to use single quotes and not double quotes, as it can result in unwanted behaviour. Integers or simple int is a whole number without a decimal point. Floating point numbers (one of the most controversial features in programming languages) is a number with a decimal point. A boolean or a bool is simply a value of true or false. They are used in conditions and many places to switch between two different actions. Later on we will discuss comparison operators, which will result in a boolean. Remember that true and 'true' and respectively false and 'false' are two different things. If you put them inside a quotation or double quotation they are considered a string and not a boolean. Just like a simple text. An array is a series of values that can be accessed using their index or pre-defined keys. So we will separate arrays in PHP into two different categories: Index-based and key-value arrays. An index-based array is simply wrapped with [ and ] and each element is separated with a comma. Values (elements) of an array in PHP can be of any type and they don't have to be the same. In order to access an element here is how we do it: Remember that indices start from 0 in PHP and not 1. (There is a logical reason behind it but it is beyond the scope of this post. Yet you can research for yourself why it starts from 0.) A key based array is defined differently. Each key-value pair is define using key => value syntax and separated by a comma again. And in order to access the value we do the same, but this time instead of an index we provide the defined key: It is good to know that most keys are strings but the values can be of any type again. It is possible to define both index-based and key-based arrays using a function-like construct named array(). What we had learnt before is just a short form for this constrcut. Arrays can hold arrays and that is what we call a multi-dimensional array.
Here is a simple one: It is good to note that a key-based array can be multi-dimensional as well: Null is a special value that means nothing. And that's it. While being simple you will see so many uses of this special value. echo() and print() are most used functions to print something to the standard output. Being a web client or simply terminal.
You can use echo and print without parentheses. Casting means converting one data type to another. For instance converting a number to a string or vice-versa. Not all data types can be converted to each other. The simple rule is that it has to make sense. (I know this is vague but consider it suffecient for now :) ). To cast a value to another type simply put the targeted type inside parentheses and before the source value: gettype() is a function that returns the data type of the variable. The list of castings are as below: If you are not seeing object in the types section above, you are completely right. Objects are more elaborate and will be discussed later in this post. Operators are used for multiple purposes, such as arithmetic (mathematical) or comparison reasons. Here are full list of PHP operators. Arithmetic operatos are used for summation, division and etc. Here is the full list: This operator is used for getting the remainder of a number divided by another. Comparison operators are used to compare two values and result in a boolean. They are used in conditions to evaluate a result. Check if two values are equal/ not equal independant of their types. You can use <> operator instead of the != operator as well. If the value on the left-hand side is less than the one on the right-hand side the result is equal to -1. If they are equal the result is equal to 0 and if the left-hand side is greater than on the right-hand side the result is equal to 1. A condition is a flow-control statement that determines if a block should be run or not, and if not any other blocks will proceed in case it is defined to do so. An if statement is simply defined as below: In place of the work condition there should be a boolean or a comparison that results in a boolean. If the boolean evaluates to true then the code inside two curly-braces ({ and }) run. An else statement is defined immediately after an if statement and the code inside its block is run in case the condition for if evaluates to false: You may also define multiple elseif statements between if and else to check other conditions: A switch case checks the value provided to it to be equal to any of its cases, and if not, the default case is triggered. It is kind of like a chained if-elseif-else statement, but only checking for equality. The code above will echo the word red as $fruit is equal to apple. After each case, there needs to be a break statement to break the switch block. The last case/default case doesn't require a break, but I always include it just for the sake of consistency. As one of my professors once said, a loop statement is the most important statement in programming, as it runs a block of code multiple times. If computers were only to do a thing once, then there would be no need for them. A for loop consists of three parts usually, an initilization, a condition and a mutator. A while loop only consists of a condition and checks if the condition is true and runs the code block if so. You may recreate a for loop using a while loop as below: A do while loop runs almost like a while loop with one difference. It runs at least once since it checks the condition afterwards and not at the beginnign. A for each loop iterates through a array. Here is the sample for an index based array: Inside the loop you may access the $el variable which is equal to each memeber of the array in each iteration. And here is an example for a key-value array: In each iteration, you may access $key and $value variables, which correspond to each key and value in the array. It is good to know that in both foreach loops demonstrated above, the names $el, $key and $value are arbitrary and can be any valid variable name you desire. A function is a block of code that can be reused, have arguments and return a value as well. A function in PHP is defined as below: In the next chapter we will discuss OOP aspect of PHP and then in the later chapter the more advanced tricks of PHP are going to be included. BTW! Check out my free Node.js Essentials E-book here: Feel free to contact me if you have any questions, projects or suggestions to improve this article. Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse CODE_BLOCK:
<?php
// CODE GOES HERE
?> Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
// CODE GOES HERE
?> CODE_BLOCK:
<?php
// CODE GOES HERE
?> CODE_BLOCK:
<?php
// CODE GOES HERE Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
// CODE GOES HERE CODE_BLOCK:
<?php
// CODE GOES HERE COMMAND_BLOCK:
<?php
// THIS IS A COMMENT
# THIS IS A COMMENT AS WELL
/*
AND THIS IS
A MULTI-LINE COMMENT
*/ Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
<?php
// THIS IS A COMMENT
# THIS IS A COMMENT AS WELL
/*
AND THIS IS
A MULTI-LINE COMMENT
*/ COMMAND_BLOCK:
<?php
// THIS IS A COMMENT
# THIS IS A COMMENT AS WELL
/*
AND THIS IS
A MULTI-LINE COMMENT
*/ CODE_BLOCK:
<?php
$i = 1;
$name = 'Adnan'; Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$i = 1;
$name = 'Adnan'; CODE_BLOCK:
<?php
$i = 1;
$name = 'Adnan'; CODE_BLOCK:
<?php
$v = 'test';
$$v = 'HELLO WORLD';
echo $test; // HELLO WORLD Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$v = 'test';
$$v = 'HELLO WORLD';
echo $test; // HELLO WORLD CODE_BLOCK:
<?php
$v = 'test';
$$v = 'HELLO WORLD';
echo $test; // HELLO WORLD CODE_BLOCK:
<?php
define(MY_CONST, 'HELLO');
echo MY_CONST; // HELLO Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
define(MY_CONST, 'HELLO');
echo MY_CONST; // HELLO CODE_BLOCK:
<?php
define(MY_CONST, 'HELLO');
echo MY_CONST; // HELLO CODE_BLOCK:
<?php
const MY_CONST = 'HELLO';
echo MY_CONST; // HELLO Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
const MY_CONST = 'HELLO';
echo MY_CONST; // HELLO CODE_BLOCK:
<?php
const MY_CONST = 'HELLO';
echo MY_CONST; // HELLO CODE_BLOCK:
<?php
$name = 'Adnan';
$last_name = 'Babakan'; Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$name = 'Adnan';
$last_name = 'Babakan'; CODE_BLOCK:
<?php
$name = 'Adnan';
$last_name = 'Babakan'; CODE_BLOCK:
<?php
$name = 'Adnan';
$test1 = 'Hi I am $name'; // Hi I am $name
$test2 = "Hi I am $name"; // Hi I am Adnan Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$name = 'Adnan';
$test1 = 'Hi I am $name'; // Hi I am $name
$test2 = "Hi I am $name"; // Hi I am Adnan CODE_BLOCK:
<?php
$name = 'Adnan';
$test1 = 'Hi I am $name'; // Hi I am $name
$test2 = "Hi I am $name"; // Hi I am Adnan CODE_BLOCK:
<?php
$i = 2;
$j = 10; Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$i = 2;
$j = 10; CODE_BLOCK:
<?php
$i = 2;
$j = 10; CODE_BLOCK:
<?php
$pi = 3.14;
$k = 7.98; Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$pi = 3.14;
$k = 7.98; CODE_BLOCK:
<?php
$pi = 3.14;
$k = 7.98; CODE_BLOCK:
<?php
$k1 = true;
$k2 = false; Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$k1 = true;
$k2 = false; CODE_BLOCK:
<?php
$k1 = true;
$k2 = false; CODE_BLOCK:
<?php
$a1 = ['Hello', 2, true, 3.14]; Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$a1 = ['Hello', 2, true, 3.14]; CODE_BLOCK:
<?php
$a1 = ['Hello', 2, true, 3.14]; CODE_BLOCK:
<?php
$a1 = ['Hello', 2, true, 3.14];
echo $a1[0]; // 'Hello'
echo $a1[1]; // 2
echo $a1[2]; // true
echo $a1[3]; // 3.14 Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$a1 = ['Hello', 2, true, 3.14];
echo $a1[0]; // 'Hello'
echo $a1[1]; // 2
echo $a1[2]; // true
echo $a1[3]; // 3.14 CODE_BLOCK:
<?php
$a1 = ['Hello', 2, true, 3.14];
echo $a1[0]; // 'Hello'
echo $a1[1]; // 2
echo $a1[2]; // true
echo $a1[3]; // 3.14 COMMAND_BLOCK:
<?php
$a2 = [ 'name' => 'Adnan', 'age' => 25
]; Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
<?php
$a2 = [ 'name' => 'Adnan', 'age' => 25
]; COMMAND_BLOCK:
<?php
$a2 = [ 'name' => 'Adnan', 'age' => 25
]; COMMAND_BLOCK:
<?php
$a2 = [ 'name' => 'Adnan', 'age' => 25
];
echo $a2['name']; // Adnan
echo $a2['age']; // 25 Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
<?php
$a2 = [ 'name' => 'Adnan', 'age' => 25
];
echo $a2['name']; // Adnan
echo $a2['age']; // 25 COMMAND_BLOCK:
<?php
$a2 = [ 'name' => 'Adnan', 'age' => 25
];
echo $a2['name']; // Adnan
echo $a2['age']; // 25 COMMAND_BLOCK:
<?php
$a1 = array('Hello', 2, true, 3.14);
$a2 = array( 'name' => 'Adnan', 'age' => 25
); Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
<?php
$a1 = array('Hello', 2, true, 3.14);
$a2 = array( 'name' => 'Adnan', 'age' => 25
); COMMAND_BLOCK:
<?php
$a1 = array('Hello', 2, true, 3.14);
$a2 = array( 'name' => 'Adnan', 'age' => 25
); CODE_BLOCK:
<?php
$m = [[1,2,3], [4,5,6], [7,8,9]];
echo $m[0][0]; // 1
echo $m[1][2]; // 6
echo $m[2][1]; // 8 Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$m = [[1,2,3], [4,5,6], [7,8,9]];
echo $m[0][0]; // 1
echo $m[1][2]; // 6
echo $m[2][1]; // 8 CODE_BLOCK:
<?php
$m = [[1,2,3], [4,5,6], [7,8,9]];
echo $m[0][0]; // 1
echo $m[1][2]; // 6
echo $m[2][1]; // 8 COMMAND_BLOCK:
<?php
$o = [ 'friends' => ['Arian', 'Ata', 'Mahdi', 'Erfan'],
];
echo $o['friends'][1]; // Ata Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
<?php
$o = [ 'friends' => ['Arian', 'Ata', 'Mahdi', 'Erfan'],
];
echo $o['friends'][1]; // Ata COMMAND_BLOCK:
<?php
$o = [ 'friends' => ['Arian', 'Ata', 'Mahdi', 'Erfan'],
];
echo $o['friends'][1]; // Ata CODE_BLOCK:
<?php
$n = null; Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$n = null; CODE_BLOCK:
<?php
$n = null; CODE_BLOCK:
<?php
echo 'Hello World';
print 'How are you doing?'; Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
echo 'Hello World';
print 'How are you doing?'; CODE_BLOCK:
<?php
echo 'Hello World';
print 'How are you doing?'; CODE_BLOCK:
<?php
$a = (string) 2;
gettype($a); // string Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$a = (string) 2;
gettype($a); // string CODE_BLOCK:
<?php
$a = (string) 2;
gettype($a); // string CODE_BLOCK:
<?php
$n = 8 + 7; // 15 Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$n = 8 + 7; // 15 CODE_BLOCK:
<?php
$n = 8 + 7; // 15 CODE_BLOCK:
<?php
$n = 10 - 3; // 7 Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$n = 10 - 3; // 7 CODE_BLOCK:
<?php
$n = 10 - 3; // 7 CODE_BLOCK:
<?php
$n = 2 * 4; // 8 Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$n = 2 * 4; // 8 CODE_BLOCK:
<?php
$n = 2 * 4; // 8 CODE_BLOCK:
<?php
$n = 10 / 2; // 5 Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$n = 10 / 2; // 5 CODE_BLOCK:
<?php
$n = 10 / 2; // 5 CODE_BLOCK:
<?php
$n = 2 ** 3; // 8 Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$n = 2 ** 3; // 8 CODE_BLOCK:
<?php
$n = 2 ** 3; // 8 CODE_BLOCK:
<?php
$n = 9 % 4; // 1 Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$n = 9 % 4; // 1 CODE_BLOCK:
<?php
$n = 9 % 4; // 1 CODE_BLOCK:
<?php
$n = "2" == 2; // true
$k = 3 == 3; // true
$o = 4 == "hello"; // false
$h = 6 != "6"; // false
$e = 6 != 5; // true Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$n = "2" == 2; // true
$k = 3 == 3; // true
$o = 4 == "hello"; // false
$h = 6 != "6"; // false
$e = 6 != 5; // true CODE_BLOCK:
<?php
$n = "2" == 2; // true
$k = 3 == 3; // true
$o = 4 == "hello"; // false
$h = 6 != "6"; // false
$e = 6 != 5; // true CODE_BLOCK:
<?php
$n = "2" === 2; // false
$k = 3 === 3; // true
$o = 4 === "hello"; // false
$h = 6 !== "6"; // true
$e = 6 !== 5; // true Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$n = "2" === 2; // false
$k = 3 === 3; // true
$o = 4 === "hello"; // false
$h = 6 !== "6"; // true
$e = 6 !== 5; // true CODE_BLOCK:
<?php
$n = "2" === 2; // false
$k = 3 === 3; // true
$o = 4 === "hello"; // false
$h = 6 !== "6"; // true
$e = 6 !== 5; // true CODE_BLOCK:
<?php
$a = 2 < 3; // true
$b = 3 < 1; // false
$c = 4 <= 4; // true Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$a = 2 < 3; // true
$b = 3 < 1; // false
$c = 4 <= 4; // true CODE_BLOCK:
<?php
$a = 2 < 3; // true
$b = 3 < 1; // false
$c = 4 <= 4; // true COMMAND_BLOCK:
<?php
$a = 4 > 1; // true
$b = 5 > 6; // false
$c = 9 >= 9; // true Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
<?php
$a = 4 > 1; // true
$b = 5 > 6; // false
$c = 9 >= 9; // true COMMAND_BLOCK:
<?php
$a = 4 > 1; // true
$b = 5 > 6; // false
$c = 9 >= 9; // true COMMAND_BLOCK:
<?php
$a = 4 <=> 5; // -1
$b = 5 <=>; // 0
$c = 6 <=> 2; // 1 Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
<?php
$a = 4 <=> 5; // -1
$b = 5 <=>; // 0
$c = 6 <=> 2; // 1 COMMAND_BLOCK:
<?php
$a = 4 <=> 5; // -1
$b = 5 <=>; // 0
$c = 6 <=> 2; // 1 CODE_BLOCK:
<?php
if (condition) { // CODE GOES HERE
} Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
if (condition) { // CODE GOES HERE
} CODE_BLOCK:
<?php
if (condition) { // CODE GOES HERE
} CODE_BLOCK:
<?php
if (condition) { // CODE GOES HERE
} else { // CODE GOES HERE
} Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
if (condition) { // CODE GOES HERE
} else { // CODE GOES HERE
} CODE_BLOCK:
<?php
if (condition) { // CODE GOES HERE
} else { // CODE GOES HERE
} CODE_BLOCK:
<?php
if(condition) { // CODE GOES HERE
} elseif (condition2) { // CODE GOES HERE
} elseif (condition3) { // CODE GOES HERE
} else { // CODE GOES HERE
} Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
if(condition) { // CODE GOES HERE
} elseif (condition2) { // CODE GOES HERE
} elseif (condition3) { // CODE GOES HERE
} else { // CODE GOES HERE
} CODE_BLOCK:
<?php
if(condition) { // CODE GOES HERE
} elseif (condition2) { // CODE GOES HERE
} elseif (condition3) { // CODE GOES HERE
} else { // CODE GOES HERE
} CODE_BLOCK:
<?php
$fruit = 'apple';
switch($fruit) { case 'banana': echo 'yellow'; break; case 'apple': echo 'red'; break; case 'cucumber': echo 'green'; break; default: echo 'NOT FOUND'; break;
} Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$fruit = 'apple';
switch($fruit) { case 'banana': echo 'yellow'; break; case 'apple': echo 'red'; break; case 'cucumber': echo 'green'; break; default: echo 'NOT FOUND'; break;
} CODE_BLOCK:
<?php
$fruit = 'apple';
switch($fruit) { case 'banana': echo 'yellow'; break; case 'apple': echo 'red'; break; case 'cucumber': echo 'green'; break; default: echo 'NOT FOUND'; break;
} CODE_BLOCK:
<?php
for($i = 0; $i < 10; $i++) { // CODE HERE RUNS FOR 10 TIMES, FROM 0 to 9.
} Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
for($i = 0; $i < 10; $i++) { // CODE HERE RUNS FOR 10 TIMES, FROM 0 to 9.
} CODE_BLOCK:
<?php
for($i = 0; $i < 10; $i++) { // CODE HERE RUNS FOR 10 TIMES, FROM 0 to 9.
} CODE_BLOCK:
<?php
while(true) { // CODE HERE RUNS FOREVER
} Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
while(true) { // CODE HERE RUNS FOREVER
} CODE_BLOCK:
<?php
while(true) { // CODE HERE RUNS FOREVER
} CODE_BLOCK:
<?php
$i = 0;
while($i < 10) { // CODE HERE RUNS FOR 10 TIMES, FROM 0 to 9. $i++;
} Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$i = 0;
while($i < 10) { // CODE HERE RUNS FOR 10 TIMES, FROM 0 to 9. $i++;
} CODE_BLOCK:
<?php
$i = 0;
while($i < 10) { // CODE HERE RUNS FOR 10 TIMES, FROM 0 to 9. $i++;
} CODE_BLOCK:
<?php
do { // CODE HERE RUNS ONCE AND THEN CHECKS THE CONDITION WHICH IS FALSE
} while (false); Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
do { // CODE HERE RUNS ONCE AND THEN CHECKS THE CONDITION WHICH IS FALSE
} while (false); CODE_BLOCK:
<?php
do { // CODE HERE RUNS ONCE AND THEN CHECKS THE CONDITION WHICH IS FALSE
} while (false); CODE_BLOCK:
<?php
$a = [10, 20, 30];
foreach($a as $el) { } Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
$a = [10, 20, 30];
foreach($a as $el) { } CODE_BLOCK:
<?php
$a = [10, 20, 30];
foreach($a as $el) { } COMMAND_BLOCK:
<?php
$k = [ "a" => 10, "b" => 20, "c" => 30
];
foreach($k as $key => $value) { } Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
<?php
$k = [ "a" => 10, "b" => 20, "c" => 30
];
foreach($k as $key => $value) { } COMMAND_BLOCK:
<?php
$k = [ "a" => 10, "b" => 20, "c" => 30
];
foreach($k as $key => $value) { } CODE_BLOCK:
<?php
function sum($a, $b) { return $a + $b;
} echo sum(10, 20); // 30 Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
<?php
function sum($a, $b) { return $a + $b;
} echo sum(10, 20); // 30 CODE_BLOCK:
<?php
function sum($a, $b) { return $a + $b;
} echo sum(10, 20); // 30 - Variables Variable variables
- Variable variables
- Constant Run-time constant
Compile-time constant
- Run-time constant
- Compile-time constant
- Types String
Integer
Float
Boolean Array Index-based array
Key-based array
Array language construct
Multi-dimensional arrays Null
- Array Index-based array
Key-based array
Array language construct
Multi-dimensional arrays
- Index-based array
- Key-based array
- Array language construct
- Multi-dimensional arrays
- Echo and Print
- Operators Arithmetic operators Summation
Subtraction
Multiplication
Division
Exponentiation
Modulo Comparison operators Equal and not equal
Identical and not identical
Less than and less than or equal
Greater than and greater than or equal
Spaceship
- Arithmetic operators Summation
Subtraction
Multiplication
Division
Exponentiation
Modulo
- Subtraction
- Multiplication
- Exponentiation
- Comparison operators Equal and not equal
Identical and not identical
Less than and less than or equal
Greater than and greater than or equal
Spaceship
- Equal and not equal
- Identical and not identical
- Less than and less than or equal
- Greater than and greater than or equal
- Conditions If
If, else and elseif
- If, else and elseif
- Switch case
- Loops For loop
While loop
Do while loop
Foreach loop
- Do while loop
- Foreach loop - Variable variables - Run-time constant
- Compile-time constant - Array Index-based array
Key-based array
Array language construct
Multi-dimensional arrays
- Index-based array
- Key-based array
- Array language construct
- Multi-dimensional arrays - Index-based array
- Key-based array
- Array language construct
- Multi-dimensional arrays - Arithmetic operators Summation
Subtraction
Multiplication
Division
Exponentiation
Modulo
- Subtraction
- Multiplication
- Exponentiation
- Comparison operators Equal and not equal
Identical and not identical
Less than and less than or equal
Greater than and greater than or equal
Spaceship
- Equal and not equal
- Identical and not identical
- Less than and less than or equal
- Greater than and greater than or equal - Subtraction
- Multiplication
- Exponentiation - Equal and not equal
- Identical and not identical
- Less than and less than or equal
- Greater than and greater than or equal - If, else and elseif - Do while loop
- Foreach loop
how-totutorialguidedev.toaimlswitchnode