Php
/
String
- 1 Basics 5
-
Quotes S
-
Constants S
-
Control structures S
-
Reference S
-
Number systems S
- 2 Variables 4
-
Definition S
-
Variable variable S
-
Exists S
-
Type casting S
- 3 Operators 5
-
Aritmetic S
-
Bitwise S
-
String S
-
Comparison S
-
Logical S
- 4 Function 4
-
Definition S
-
Anonymous S
-
Reference S
-
Variable arguments S
- 5 Array 7
-
Basics S
-
Operations S
-
Create S
-
Search S
-
Modify S
-
Sort S
-
Storage S
- 6 String 9
-
Basics
-
Compare
-
Search
-
Replace
-
Format
-
Regexp
-
Parse
-
Formating
-
Json
- 7 Streams 6
-
File open
-
Read file
-
Read csv
-
File contents
-
Context
-
Ob_start
- 8 Oop 6
-
Object instantiation S
-
Class constructor
-
Interfaces, abstract
-
Resource visibility
-
Class constants
-
Namespaces
- 9 Features 9
-
Autoload
-
Class reflection
-
Magic methods
-
Exceptions S
-
Late static binding
-
Type hinting
-
SPL
-
PHPUNIT
-
PHAR
- 10 Versions 2
-
Php7.4 S
-
Php8.0 S
- 11 Http 4
-
Headers
-
File Uploads
-
Cookies
-
Sessions
- 12 Design Patterns 4
-
Singleton Pattern S
-
Observer Pattern
-
Strategy Pattern
-
Registry
- 13 Modern Php 8
-
Composer S
-
Slim Framework
-
Autoloader
-
Package
-
Releases
-
Generators
-
Dependency Injection
-
Middleware
- 14 Create Framework 7
-
App
-
Http Foundation
-
Front Controller
-
Routing
-
Render Controller
-
Resolver
-
SoC
- 15 Frameworks 4
-
Symfony v5
-
Laravel v8
-
Laminas v3
-
Codeigniter v4
- 16 Composer 5
-
Guzzle
-
Carbon
-
Faker
-
Math
-
Requests
- 17 Symfony 6
-
Routes S
-
Annotations
-
Flex
-
Controllers
-
Doctrine
-
Templating
R
Q
Signle quotes
Single quotes will be recorded as is
code
$a = 'a';
echo $b = '$a n'; // $a n
Double quotes
Double quotes will be interpreted and replaced
code
$b = 'b';
echo $b = "$b n"; // b n
Braces
Braces are used when parser is not able to parse a variable
code
$a[1] = 'Smith';
echo "John {$a[1]}[1974]"; // John Smith[1974]
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 (;).
code
// Allows the use of quotes without escaping
$who = "John";
$output = <<<TEST
She said "This is $who's test"
on multiple rows
<span class='keyword_code'>TEST;</span>
echo nl2br($output);
/* output
She said "This is John's test"
on multiple rows
*/
Nowdoc
With Nowdoc formating no parsing is done inside.
code
$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
*/
Length
All characters in the string are counted, regardless of their value.
code
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
Concatation
Concatation with comma is faster then dot.
code
echo "a" . "b"; // Output: ab
echo "a" , "c"; // Output: ac
Using Strings as Arrays
code
$str = "abcdef";
echo $str[1]; // b
Conversion
String automatic conversion
code
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
Operator Precedence and Associativity
* / % <span class='keyword_code'>Highest Precedence</span>
+ - .
< <= > >=
= = = != =
&&
||
And
XOR
OR Lowest Precedence
code
// */%
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
➥ Questions