Skip to content

Instantly share code, notes, and snippets.

@shin1x1
Created December 18, 2020 01:23
Show Gist options
  • Select an option

  • Save shin1x1/c6b157fb0ef065c32d950c796022eb1f to your computer and use it in GitHub Desktop.

Select an option

Save shin1x1/c6b157fb0ef065c32d950c796022eb1f to your computer and use it in GitHub Desktop.

Revisions

  1. shin1x1 created this gist Dec 18, 2020.
    24 changes: 24 additions & 0 deletions if_expression.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    <?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);