LoginSignup
2
0

More than 5 years have passed since last update.

PHPのイコール2つで比較する時の罠

Posted at

(前提)
弊プロジェクトでは===は使わずに==を使う慣習があります

<?php

$str = "0";
$cmp = "test";
var_dump($str == $cmp); // false

$str = 1;
$cmp = "test";
var_dump($str == $cmp); // false

$str = 0;
$cmp = "test";
var_dump($str == $cmp); // なんとtrueになる!

2
0
1

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
2
0