PROGRAMMING

 
REMEMBERS




Last update:   29-10-2021

Quotes

Signle quotes

Single quotes will be recorded as is
 
$a = 'a';
echo $b = '$a n'; // $a n

Double quotes

Double quotes will be interpreted and replaced
 
$b = 'b';
echo $b = "$b n"; // b n

Braces

Braces are used when parser is not able to parse a variable
 
$a[1] = 'Smith';
echo "John {$a[1]}[1974]"; // John Smith[1974]
Herodoc    (2/5)

Herodoc

Herodoc formating is similar with double quotes, but for multiple lines. It is very important to note that the line with the closing identifier must contain no other characters, except possibly a semicolon (;).
 
// Allows the use of quotes without escaping

$who = "John";
$output = <<<TEST
    She said "This is $who's test"
    on multiple rows
TEST;

echo nl2br($output);
    /* output
    She said "This is John's test"
    on multiple rows
    */
... 6 lines
 

Nowdoc

With Nowdoc formating no parsing is done inside.
 
$who = "John";
$str = <<<'TEST'
    She said "This is $who's test" 
    on multiple rows
TEST;

echo nl2br($str);
    /* Outputs:
        She said "This is $who's test"
        on multiple rows
    */
... 5 lines
 
Length    (3/5)

Length

All characters in the string are counted, regardless of their value.
 
echo strlen("abc"); // 3

echo strlen(""); // 0
echo strlen(" "); // 1

echo strlen("n"); // 1
echo strlen('n'); // 1

echo strlen(NULL); // 0
echo strlen(0); // 1

echo strlen(TRUE); // 1
echo strlen(FALSE); // 0
... 4 lines
 
Concatation    (4/5)

Concatation

Concatation with comma is faster then dot.
 
echo "a" . "b"; // Output: ab
echo "a" , "c"; // Output: ac
Using Strings as Arrays
 
$str = "abcdef";
echo $str[1]; // b

Conversion

String automatic conversion
 
echo "a" . "b"; // ab
echo 1 . 2; // 12

echo "a" + "b"; // 0    
echo "a" + 1; // 0 + 1 = 1

echo "a" * 2; // 0 * 2 = 0
Precedence    (5/5)

Precedence

Operator Precedence and Associativity
 
 * / %     Highest Precedence
+ - .     
< <= > >=      
= = = != =      
&&      
||      
And      
XOR      
OR     Lowest Precedence
... 4 lines
 
 
// */%
echo 10 / 2 * 5 % 7; // 4
    // 5 * 5 % 7 
    // 25 % 7 = 4

// + - .
echo "aa" . 1 + 2 . 'b'; // 2b
    // "aa1" + 2 . 'b'
    // 0 + 2 . 'b' = 2b

// * / % precedence over  + - .
echo "aa" . 1 * 2 . '0'; // aa20

// + - . precedence over > <
echo 3 - 2 < 2 ; // 1
echo 3 - (2 < 2) ; // 3
... 8 lines
 

Questions    
String compare

        A B C D E F
🔔
1/6