Jump to content

Archived

This topic is now archived and is closed to further replies.

holowugz

Conditional statement

Recommended Posts

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?

Share this post


Link to post
Share on other sites
get rid of the second equals sign and you should be all set.


best-
j.

Share this post


Link to post
Share on other sites
[!--quoteo(post=357156:date=Mar 22 2006, 12:47 AM:name=jeepin81)--][div class=\'quotetop\']QUOTE(jeepin81 @ Mar 22 2006, 12:47 AM) [snapback]357156[/snapback][/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?

Share this post


Link to post
Share on other sites
[!--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 [code]<?php $x = 0;
if ($x == false) echo "true"; else echo "false" ?>[/code]
will print "true", while this code
[code]<?php
$x = 0;
if ($x === false)echo "true"; esle echo "false" ?>[/code]
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.