mirror of
https://github.com/namibia/awesome-cheatsheets.git
synced 2024-11-27 15:26:31 +00:00
Some more
This commit is contained in:
parent
014126e4d7
commit
d5b2d4abb6
@ -65,6 +65,25 @@ ksort($arr); // Sort associative arrays in ascending order, according to the key
|
||||
arsort($arr); // Sort associative arrays in descending order, according to the value.
|
||||
krsort($arr); // Sort associative arrays in descending order, according to the key.
|
||||
|
||||
/**
|
||||
* Conditions
|
||||
*/
|
||||
|
||||
// If/Elseif/Else
|
||||
if($i > 10) {
|
||||
|
||||
} elseif( $i > 100) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
// Ternary
|
||||
$string = $state == 'Running' ? 'He is running' : 'I don\'t know';
|
||||
|
||||
// Null coalescing
|
||||
$string = $startDate ?? '';
|
||||
|
||||
/**
|
||||
* Ways of looping
|
||||
*/
|
||||
@ -144,6 +163,31 @@ $_ENV; // php.ini options
|
||||
$argv; // Array of terminal arguments (filename included)
|
||||
$argc; // Number of arguments passed into terminal
|
||||
|
||||
/**
|
||||
* Functions
|
||||
*/
|
||||
|
||||
// Simple function
|
||||
function name($parameter);
|
||||
|
||||
// Function with return type (void, int, float, string, array, object, mixed)
|
||||
function name($parameter) : void;
|
||||
|
||||
// Function with optionnal parameter
|
||||
function name($parameter = '') : string;
|
||||
|
||||
// Function with typed parameter (? means "can be null")
|
||||
function name(?string $parameter) : ?string;
|
||||
|
||||
// Function with union types (PHP >= 8.0)
|
||||
function name(int|string $parameter1, array $parameter2) : int|string;
|
||||
|
||||
// Function call
|
||||
name('my_parameter');
|
||||
|
||||
// Null safe operator (PHP >= 8.0)
|
||||
$myObject?->getName()?->startWith('A');
|
||||
|
||||
/**
|
||||
* Class
|
||||
* http://php.net/manual/en/language.oop5.basic.php
|
||||
|
Loading…
Reference in New Issue
Block a user