Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What are the problem?

posted at

updated at

Organization

PHP swithc文で型比較に対応する

目的

  • PHPのswitch文で詰まった部分を簡単にまとめる

前提情報

詳細

  • 下記のように記載することで$fooにstringの1かintの1かを厳密に比較する事ができる。

    <?php
    
    switch (true) {
        case $foo === 1:
            echo 'int';
            break;
        case $foo === '1':
            echo 'string';
            break;
    }
    ?>
    
  • $fooにintの1が格納されている時には「int」と表示され、stringの1が格納されているときには「string」と表示される。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
0
Help us understand the problem. What are the problem?