switch (true) { case $hoge === 1: //$hogeが数値の場合のみ実行される break; case $hoge === '1': //$hogeが文字列の場合のみ実行される break; } Register as a new user and use Qiita more conveniently You get articles that match your needsYou can efficiently read back useful informationYou can use dark themeWhat you can do with signing up