Jump to content

IPS Shirt Design


Charles

Recommended Posts

  • Replies 170
  • Created
  • Last Reply

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.
Link to comment
Share on other sites


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.
Link to comment
Share on other sites

In most instances, you would be doing something like

if ( $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.

Link to comment
Share on other sites

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. <_<

Link to comment
Share on other sites


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...
Link to comment
Share on other sites

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 }




Link to comment
Share on other sites

Archived

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

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...