Skip to content

Instantly share code, notes, and snippets.

@shin1x1
Created December 18, 2020 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shin1x1/c6b157fb0ef065c32d950c796022eb1f to your computer and use it in GitHub Desktop.
Save shin1x1/c6b157fb0ef065c32d950c796022eb1f to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
$i = random_int(1, 2);
var_dump($i);
// match expression
$ret = match ($i % 2 === 0) {
true => 'even',
false => 'odd',
};
var_dump($ret);
// ternary Operator
$ret = $i % 2 === 0 ? 'even' : 'odd';
var_dump($ret);
// if statement
if ($i % 2 === 0) {
$ret = 'even';
} else {
$ret = 'odd';
}
var_dump($ret);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment