LoginSignup
0
1

More than 3 years have passed since last update.

便利な評価方法 By php

Last updated at Posted at 2021-04-13

はじめに

phpを使う上でよくemptyやis_null、issetを使うが、完全に条件を覚えていないので簡単に見返せるよう、自分用に書く。

empty

emptyは厳しい

bool
$checkVal=1 false
$checkVal='1' false
$checkVal=0 true
$checkVal='0' true
$checkVal=[] true
$checkVal=[0] false
$checkVal true
$checkVal='' true
$checkVal=null true

is_null

is_nullはゆるい

bool
$checkVal=1 false
$checkVal='1' false
$checkVal=0 false
$checkVal='0' false
$checkVal=[] false
$checkVal=[0] false
$checkVal true
$checkVal='' false
$checkVal=null true

if

ifは厳しい

bool
$checkVal=1 true
$checkVal='1' true
$checkVal=0 false
$checkVal='0' false
$checkVal=[] false
$checkVal=[0] true
$checkVal false
$checkVal='' false
$checkVal=null false

isset

issetはゆるい

bool
$checkVal=1 true
$checkVal='1' true
$checkVal=0 true
$checkVal='0' true
$checkVal=[] true
$checkVal=[0] true
$checkVal false
$checkVal='' true
$checkVal=null false

総評

isがついてたらゆるい

empty is_null if isset
$checkVal=1 false false true true
$checkVal='1' false false true true
$checkVal=0 true false false true
$checkVal='0' true false false true
$checkVal=[] true false false true
$checkVal=[0] false false true true
$checkVal true true false false
$checkVal='' true false false true
$checkVal=null true true false false
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1