Skip to content

Instantly share code, notes, and snippets.

@naoto
Created January 5, 2011 09:03
Show Gist options
  • Save naoto/766079 to your computer and use it in GitHub Desktop.
Save naoto/766079 to your computer and use it in GitHub Desktop.
PHPによるCASTのマジック

String => Integer

$hoge = "abc";
if(0 == $hoge)
    echo "true";
else
    echi "false";

>> true

これはPHPのCASTで変換できなかった場合0を返す仕様のため

参照

文字列の最初の部分により値が決まります。文字列が、 有効な数値データから始まる場合、この値が使用されます。その他の場合、 値は 0 (ゼロ) となります。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment