标签: php if-statement compare
$a['id'] = 124; $b['id'] = '124'; if ($a['id'] == $b['id']) {}
在这种情况下,我希望id等于。如何正确比较string和int为int? 有优雅的方法吗?
答案 0 :(得分:1)
将字符串值解析为整数,如下所示:
if($a['id'] == (int)$b['id']) { // notice `(int)` which will make the '124' to int 124 }