Php
/
Basics
- 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
S
R
Q
Php Basics Number Systems
Decimal 1452 Octal 644 Binary 110100100 Hexadecimal 0xFF
Decimal
An integer can be specified in decimal, base 10
echo 10; // 10
echo -1; // -1
echo 0; // 0
echo 1452; // 1452
Octal
We use octal when we need a readable format for bit string in group of 3.
rw-r--r-- = 110100100 (binary) = 644 (octal) # Unix access permision - 0755
READ (1) WRITE (1) EXEC (1) = binary 111 = octal 7
READ (1) WRITE (1) EXEC (0) = binary 110 = octal 6
READ (1) WRITE (0) EXEC (0) = binary 100 = octal 4
97 (decimal) = 141 (octal) # To convert decimal to octal, use modulus
97 % 8 => reminder 1
12 % 8 => reminder 4
1 % 8 => reminder 1
1*8^2 + 4*8^1 + 1*8^0 = 64 + 32 + 1 = 97
Binary
To conver binary to octal, convert first to decimal, then to octal.
echo 0b110100100; // 420 - decimal
echo bindec(110100100); // 420 - decimal
echo decoct(0b110100100); // 644 - octal
echo 0644;
// 6*8^2 + 4*8^1 + 4*8^0
// 384 + 32 + 4
// 420
echo 0b1010111100;
// 700
// 001 010 111 100
// 00 are added to complete group of 3 bits
// 001 010 111 100 (binary) = 1274 (octal)
Hexadecimal
Base 16 notation, identified by its leading 0x.
/**
* Hex numbers are often used to represent colours.
* Orange is represented as #FFA500 (255 red, 165 green, 0 blue).
*/
echo 0x121; // 1*16^2 + 2*16^1 + 1*16^0 = 256 + 32 + 1 = 289
echo 0xFF; // 15*16^1 + 15*16^0 = 240 + 15 = 255
Float
Be aware that the float data type is not always capable of representing numbers.
/**
* Float data type is not always capable of representing numbers.
* The result of this simple expression is stored internally as 7.999999
*/
echo (0.1 + 0.7) * 10; // 8
echo (int) ((0.1 + 0.7) * 10); // 7
➥ Questions
Last update: 60 days ago