Jump to content

if $type


willdikuloz

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?
Link to comment
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]
Link to comment
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)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.