[SOLVED] && || valid in PHP?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
arya6000
Forum Newbie
Posts: 15
Joined: Fri Apr 07, 2006 3:32 pm

[SOLVED] && || valid in PHP?

Post by arya6000 »

Hi

I'm a C programmer and I'm learning php now, I wrote a program something like

Code: Select all

 
while($row = mysql_fetch_array($result) && $i < 250)
{
....
.....
}
 
But it does not work. I tried to find some reference online for using && and || in php loops and I did not find anything. Does php support && and || in loops?

Thank You
Last edited by arya6000 on Thu Feb 05, 2009 9:13 pm, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: && || valid in PHP?

Post by John Cartwright »

Indeed PHP does support both. More info can be found on the operators page, and more specifically the logical operators page.

PHP also supports AND and OR, although they hold different precedence.

Can you define "does not work"?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: && || valid in PHP?

Post by requinix »

John Cartwright wrote:PHP also supports AND and OR, although they hold different precedence.
Yay! Only thing missing is a link to the operator precedence page.

As a C programmer you should be familiar with the concept of precedence. Notice how && is higher in the table than =?
arya6000
Forum Newbie
Posts: 15
Joined: Fri Apr 07, 2006 3:32 pm

Re: && || valid in PHP?

Post by arya6000 »

ok, thanks it working now.

All I needed was to put them in brackets like

while(($row = mysql_fetch_array($result)) && ($i < 250))
User avatar
Skoalbasher
Forum Contributor
Posts: 147
Joined: Thu Feb 07, 2008 8:09 pm

Re: && || valid in PHP?

Post by Skoalbasher »

arya6000 wrote:ok, thanks it working now.

All I needed was to put them in brackets like

while(($row = mysql_fetch_array($result)) && ($i < 250))
Doh! lol
Post Reply