From d5b2d4abb640aee277048aeac339422a9a1ec52f Mon Sep 17 00:00:00 2001 From: Jugid Date: Wed, 1 Dec 2021 23:04:16 +0100 Subject: [PATCH] Some more --- languages/php.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/languages/php.php b/languages/php.php index def6f0c..83d8da2 100644 --- a/languages/php.php +++ b/languages/php.php @@ -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