Jump to content


Photo

Conditional statement


  • Please log in to reply
3 replies to this topic

#1 holowugz

holowugz
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 22 March 2006 - 12:41 AM

Hell again guys,

ok this is my conditional statementL

if($class !== 7) {
header("Location: ". $redirectSuccess);
exit;
}

basically i am saying if $class is not 7 follow that instruction but it cycles through the statement anyway, what i am testing it on the vlaue of class is DEFINITELY 7

any ideas?

#2 jeepin81

jeepin81
  • Members
  • Pip
  • Newbie
  • 6 posts
  • LocationChi-Town - Go Cubs and Go Bears

Posted 22 March 2006 - 12:47 AM

get rid of the second equals sign and you should be all set.


best-
j.

#3 holowugz

holowugz
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 22 March 2006 - 12:56 AM

[!--quoteo(post=357156:date=Mar 22 2006, 12:47 AM:name=jeepin81)--][div class=\'quotetop\']QUOTE(jeepin81 @ Mar 22 2006, 12:47 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
get rid of the second equals sign and you should be all set.
best-
j.
[/quote]

...? , i thought == is the comparison operator and = was the operator to set something to something:

i.e $var = 7 (Is set To)
if($var == 7) (if Var equals 7)

does it differ in an if statement then?

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 22 March 2006 - 01:51 AM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]...? , i thought == is the comparison operator and = was the operator to set something to something:

i.e $var = 7 (Is set To)
if($var == 7) (if Var equals 7)
[/quote]
Yes, that is true, but we're looking at conditional operators:
== equal values
!= not equal values
=== equal types
!== not equal types

The difference here is usefull when comparing a return of "false" to a return of 0
This code
<?php $x = 0;
if ($x == false) echo "true"; else echo "false" ?>
will print "true", while this code
<?php
$x = 0;
if ($x === false)echo "true"; esle echo "false" ?>
will print "false".

The first is comparing the values " 0 == 0" (false has the value of 0)
The second is comparing types " integer != boolean "

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users