1
1
mirror of https://github.com/namibia/awesome-cheatsheets.git synced 2024-11-24 05:37:39 +00:00

Some more

This commit is contained in:
Jugid 2021-12-01 23:04:16 +01:00
parent 014126e4d7
commit d5b2d4abb6

View File

@ -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. arsort($arr); // Sort associative arrays in descending order, according to the value.
krsort($arr); // Sort associative arrays in descending order, according to the key. 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 * Ways of looping
*/ */
@ -144,6 +163,31 @@ $_ENV; // php.ini options
$argv; // Array of terminal arguments (filename included) $argv; // Array of terminal arguments (filename included)
$argc; // Number of arguments passed into terminal $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 * Class
* http://php.net/manual/en/language.oop5.basic.php * http://php.net/manual/en/language.oop5.basic.php