Jump to content


Photo

if $type


  • Please log in to reply
4 replies to this topic

#1 willdikuloz

willdikuloz
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 08 June 2006 - 12:29 AM

if ( $type == link ) {
echo '
<tr><td width="50"><img src="' .$type. '.gif"></td><td width="340"><a href="' .$link. '" target="_blank" class="postlink">' .$title. '</a></td><td width="50"><font size="1" face="verdana" color="#A5A5A5"><i>' .$dat. '</i></font></td></tr>
';
} 
else {
echo '
<tr><td width="50"><img src="' .$type. '.gif"></td><td width="340"><a href="view.php?view=' .$post. '" class="postlink">' .$title. '</a></td><td width="50"><font size="1" face="verdana" color="#A5A5A5"><i>' .$dat. '</i></font></td></tr>
';
}

is it possible to put two words for example
if ( $type == link OR image )

obviously "OR" doesn't work but is there anyway for it to look for 2 variables at one time?

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 08 June 2006 - 01:09 AM

if ($type == 'link' || $type == 'image')

Also there are the [!--coloro:blue--][span style=\"color:blue\"][!--/coloro--]boolean or[!--colorc--][/span][!--/colorc--] " || " and the [!--coloro:blue--][span style=\"color:blue\"][!--/coloro--]logical or[!--colorc--][/span][!--/colorc--] " or "; there is a very small difference between them. [thanks thorpe]

~ D Kuang

#3 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 08 June 2006 - 02:53 AM

or is fine though is further down in precedence and may work a little differently.
if ($type == 'link' or $type == 'image')


#4 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 08 June 2006 - 04:05 AM

[a href=\"http://www.php.net/manual/en/language.operators.logical.php\" target=\"_blank\"]Logical Operators[/a]

The reason for the two different variations of "and" and "or" operators is that they operate at different precedences. (See Operator Precedence.)

[a href=\"http://www.php.net/manual/en/language.operators.php#language.operators.precedence\" target=\"_blank\"]Operator Precedence[/a]

The logical "or" is fine, but keep in mind that it's lower in precedence than the assignment operators.

of course this should be clear, but i think it has to be mentioned espacially:

AND is not the same like &&

for example:

<?php $a && $b || $c; ?>
is not the same like
<?php $a AND $b || $c; ?>

the first thing is
(a and b) or c

the second
a and (b or c)

'cause || has got a higher priority than and, but less than &&

of course, using always [ && and || ] or [ AND and OR ] would be okay, but than you should at least respect the following:

<?php $a = $b && $c; ?>
<?php $a = $b AND $c; ?>

the first code will set $a to the result of the comparison $b with $c, both have to be true, while the second code line will set $a like $b and THAN - after that - compare the success of this with the value of $c

maybe usefull for some tricky coding and helpfull to prevent bugs :D

greetz, Warhog


(From PHP user notes)
~ D Kuang

#5 willdikuloz

willdikuloz
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 08 June 2006 - 03:14 PM

thanks alot, btw Jin > every other character in Marvel v Capcom period.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users