Jump to content

Archived

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

willdikuloz

if $type

Recommended Posts

[code]
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>
';
}[/code]

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

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

Share this post


Link to post
Share on other sites
[code]if ($type == 'link' || $type == 'image')[/code]

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]

Share this post


Link to post
Share on other sites
[i]or[/i] is fine though is further down in precedence and may work a little differently.
[code]
if ($type == 'link' or $type == 'image')
[/code]

Share this post


Link to post
Share on other sites
[a href=\"http://www.php.net/manual/en/language.operators.logical.php\" target=\"_blank\"]Logical Operators[/a]

[quote]The reason for the two different variations of "and" and "or" operators is that they operate at different precedences. (See Operator Precedence.) [/quote]
[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.

[quote]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 [/quote]

(From PHP user notes)

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.