-
[PHP & Codeigniter] Comparison operator problem 비교 연산자 문제PHP & Codeigniter 2018. 12. 25. 16:50
php 에서는,
보통 == 은 그냥 그대로고,
=== 은 데이터는 물론 데이터 타입까지 체크를 한다.
이걸 알나낸 계기가
0 == 'admin' 이라고 했을때, == 로 하면 'admin' 을 타입캐스팅을 해버리기 때문에 true 가 return 이 된다(0=0)
그래서 === 로 체크 하면 된다, 즉 왼쪽 기준으로 오른쪽의 데이터 타입을 맞추기 때문에.
Normally, '==' is same as the other languages, but in PHP there're some problem for type casting.
When you try 0 == 'admin', you think this is false, but these are difference type of variables, so going to be '0' (i.g. 0 == 0, so it's true)
So if you don't know data types, you should use ===
'PHP & Codeigniter' 카테고리의 다른 글
[PHP & Codeigniter] Session lost 세션실종 (0) 2018.12.25 [PHP & Codeigniter] POST array in PHP 배열 post 통신 (0) 2018.12.25 [PHP & Codeigniter] Making Ant for Eclipse PHP Developer Ant를 FTP 로 사용 (0) 2018.12.25 [PHP & Codeigniter] Log 를 남겨보자 (0) 2018.12.25 댓글