Memory App
Programming
 




Single quotes

Single quotes will be recorded as is

$a = 'a';
echo $b = '$an'; // output $an
(1/7)

Double quotes

Double quotes will be interpreted and replaced

$a = 'a';
echo $b = "$an"; // output a
(2/7)

Braces

Braces are used when parser is not able to parse a variable

$a[1] = 'Smith';
echo "John {$a[1]}[1974]"; // John Smith[1974]
(3/7)

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
    */
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
    */
(4/7)

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
(5/7)

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
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
(6/7)

Precedence

Operator Precedence and Associativity

 * / %     Highest Precedence
+ - .     
< <= > >=      
= = = != =      
&&      
||      
And      
XOR      
OR     Lowest Precedence

// */%
echo 10 / 2 * 5 % 7; 
    // 5 * 5 % 7 = 25 % 7 = 4
    // Output: 4    

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

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

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


Questions



Top Reference > Programming
0/0 (80)  
Not Logged