and && or ||

Started on the old forum in July 2011 · view the original in the archive · old links redirect here

7 replies · 1,190 views · started 15 years ago · 1 min read

4 participants
arnage Lead · 811 posts #1

"and" is not the same like && , also, "or" is not same like ||

&& is higher priority than "and" , also, || is higher priority than "or".

For example:

$a && $b || $c;

is not the same like:

$a and $b || $c;

the first thing is: (a and b) or c

the second: a and (b or c)

Because || has got a higher priority than and, but less than && .

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

$a = $b && $c;
$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 .

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
mFreak Developer · 66 posts #3

CreativityKills wrote: i dnt undastand wth u talkn about. I use and and or, easier to read.

Its like mats, look it this way

and is + or is - && is * || is /

you probably know that is you have an expresion a+bc=d its the same as a+(bc)=d not the (a+b)*c=d. the * simply have a priority over + and is checked first. same is with 'and' and '&&'

$("#mfreak").find(".head brain").clone();

Progress:

[|||___________________________] : 5%

Output:

Memory limit reached, unable to complete operation.

Support answer:

Try using a super uber strong mega computer to reach at least 10%.

👋

arnage Lead · 811 posts #4

CreativityKills wrote: i dnt undastand wth u talkn about. I use and and or, easier to read.

Look at this example from my site script:

if (!empty($a) and check_it($a) || strlen($a) != 32) { exit(errors()); }

if u write it like this:

if (!empty($a) && check_it($a) || strlen($a) != 32) { exit(errors()); }

index page will not open, this is gonna end up with exit; always because of priority. Its not the same.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
subzero Super moderator Fellow · 3,954 posts #5

Most of my scripts use || and && i never used (AND OR OR)

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

arnage Lead · 811 posts #6

Me too until i came across this particular problem, when i researched a bit and used only once "and" in the script insted &&.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
CreativityKills Lead · 833 posts #7

arnage wrote: Look at this example from my site script:

if (!empty($a) and check_it($a) || strlen($a) != 32) { exit(errors()); }

if u write it like this:

if (!empty($a) && check_it($a) || strlen($a) != 32) { exit(errors()); }

index page will not open, this is gonna end up with exit; always because of priority. Its not the same.

i undastand bt really it boils down to coding style. Me i usually take note of that, so i make use of brackets to tell php which i wana run 1st.

// this
$calc = 66 + 20 * 8;

// is not
$calc = 66 + (20 * 8);

// ur examply my way
if ( ( isset($a) AND ! empty($a) AND check_it($a) ) OR strlen($a) !== 32) {
exit(errors());
}

Sign in to reply.

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close