Wolfie Posted July 22, 2010 Posted July 22, 2010 theres issues with this, should be....if ( $community == 'Invision Power Board' ) { $you = "Cool"; } else { $you = "n00b"; } Either way works. Of course, it could also be if ( $you == $cool ) and refer to IPB.
Jaggi Posted July 22, 2010 Posted July 22, 2010 Either way works. Of course, it could also be if ( $you == $cool ) and refer to IPB. of course in an ideal world it'd be: if ( $community = 'Invision Power Board' ) { $you = "Cool"; } else { $you = "n00b"; }
DawPi Posted July 22, 2010 Posted July 22, 2010 of course in an ideal world it'd be: if ( $community = 'Invision Power Board' ) { $you = "Cool"; } else { $you = "n00b"; } if ( $community = 'Invision Power Board' ) Very good coder. :lol: ;)
Fishfish0001 Posted July 22, 2010 Posted July 22, 2010 if ( $community == 'Invision Power Board' ) *cough cough*
Jaggi Posted July 23, 2010 Posted July 23, 2010 if ( $community = 'Invision Power Board' ) Very good coder. :lol: ;) if ( $community == 'Invision Power Board' ) *cough cough* obviously i'm faced with newbs here (yea i said it :P). Idea was to say that everyones community always is ipb, hence "in an ideal world" :P.
Wolfie Posted July 24, 2010 Posted July 24, 2010 But the syntax... [img] [/img] What about it? It looks fine to me as far as PHP syntax is concerned.
Collin1000 Posted July 24, 2010 Posted July 24, 2010 What about it? It looks fine to me as far as PHP syntax is concerned. if statements require a double equal. so if ($wolifie = "awesome") in incorrect. it should be if ($wolifie == "awesome")
Wolfie Posted July 24, 2010 Posted July 24, 2010 if statements require a double equal. so if ($wolifie = "awesome") in incorrect. it should be if ($wolifie == "awesome") You can do a single = in there. It would only change how it works (ie wouldn't be comparing the value, but rather setting it and on success the condition would be true). So in a perfect world, $community would always be set to Invision Power Board, so you wouldn't need to compare it, only set it.
Lewis P Posted July 24, 2010 Posted July 24, 2010 Yeah, you still don't require a double == in there, a single = works fine. Try it some day.$var = 'hello; echo $var; // hello if( $var = 'goodbye' ) { echo $var; //goodbye }
Collin1000 Posted July 24, 2010 Posted July 24, 2010 Yeah, you still don't require a double == in there, a single = works fine. Try it some day.$var = 'hello; echo $var; // hello if( $var = 'goodbye' ) { echo $var; //goodbye } how come every manual everywhere uses two?
Lewis P Posted July 24, 2010 Posted July 24, 2010 Honestly, I don't know. It's probably because the chance of you needing something to evaluate to TRUE is small, and that it's not really needed. Checked php.net though?
Wolfie Posted July 24, 2010 Posted July 24, 2010 In most instances, you would be doing something likeif ( $imagesize = getimagesize( $filename ) ) { (code to parse) } So long as there's no error and $imagesize is filled with data, then the condition is true. Take a look at this code: http://php.net/manual/en/function.fopen.php if(($fh = fopen($rssFile,'w')) === FALSE){ die('Failed to open file for writing!'); } It's setting $fh to be the value of the file handler and if it fails (FALSE), then it executes.
Enkidu Posted July 24, 2010 Posted July 24, 2010 Now I do agree that a single = is pragmatically correct but I fail to see the point of doing such a thing, because the else part of the if statement will never be executed unless there is a mysterious case where $community = 'Invision Power Board' would evaluate to false. <_<
Wolfie Posted July 24, 2010 Posted July 24, 2010 Now I do agree that a single = is pragmatically correct but I fail to see the point of doing such a thing, because the else part of the if statement will never be executed unless there is a mysterious case where $community = 'Invision Power Board' would evaluate to false. <_< pssst, it's this thing called a joke...
Wolfie Posted July 25, 2010 Posted July 25, 2010 which part? if ( $community = 'Invision Power Board' ) { $you = "Cool"; } else { $you = "n00b"; }
Wolfie Posted July 25, 2010 Posted July 25, 2010 As a matter of fact, Mister Data, it's something that requires a sense of humor to get. <_<
Guest Posted July 25, 2010 Posted July 25, 2010 And yet another topic is totally derailed. -1 for "My other account is Wolfie"
Mark Posted July 25, 2010 Posted July 25, 2010 I think Jaggi's joke went over a lot of heads :P how come every manual everywhere uses two? They're different things. A single = is of course an assignment operator, a double (or triple) = is a comparison operator. This is completely valid code: if ( $foo = bar() ) { // Is executed if bar() returns true. $foo is now true. } else { // Is executed if bar() returns false. $foo is now false. } On the other hand: if ( $foo == bar() ) { // Is executed if bar() returns the same value as whatever $foo is } else { // Is executed if bar() returns a different value as whatever $foo is }
Recommended Posts
Archived
This topic is now archived and is closed to further replies.