Connecting Tech Pros Worldwide Forums | Help | Site Map

need help about php variable

Newbie
 
Join Date: Nov 2007
Posts: 15
#1: Mar 24 '08
[PHP]<?php
if ($check!==$_SESSION["validate"]){echo 'Validation is not ok';}
else { echo 'OK';}
?>[/PHP]
the above doesn't work

but the below work
[PHP]<?php
if ($check==$_SESSION["validate"]){echo 'ok';}
else { echo 'validadation is not OK';}
?>[/PHP]


How the variables work logically with 'if' in PHP??? strange

The below also works

[PHP]if (strcmp($check,$_SESSION['validation'])==0){echo 'ok';} else {echo 'validation is not OK';}[/PHP]

ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#2: Mar 24 '08

re: need help about php variable


== means: value is equal: $a == $b Equal TRUE if $a is equal to $b.
=== means: value and data type must be equal: TRUE if $a is equal to $b, and they are of the same type.

See the php manual on comparison operators

Ronald
Newbie
 
Join Date: Nov 2007
Posts: 15
#3: Mar 24 '08

re: need help about php variable


Thanks very much, actually, not because of it..

by using strcmp we don't need to trim the string, but i don't know why if i use ==, i have to trim it, by using the below, it works

[PHP]<?php
if (trim($check!)!==trim($_SESSION["validate"])){echo 'Validation is not ok';}
else { echo 'OK';}
?>[/PHP]
Reply