Discover and share the best of the web!
Learn more about Digg by taking the tour.
Operators In PHP
howtoforge.com — This article is the second of a series of PHP guides that aim at teaching you the basics of PHP programming. Today we are going to discuss different types of operators used in PHP. I hope you remember the basic definition of the operators and operands from my last article (PHP Programming Basics).
- 627 diggs
- digg it
- jrepin, on 10/12/2007, -6/+7Previous part:
http://digg.com/programming/PHP_Programming_Basics- lqqkout4elfy, on 10/12/2007, -3/+5Yo, it seems Haroon's tutorials are flawed with typos! This means, you WILL learn the wrong thing if you went to this site!!
Buried for inaccurate info. - trghpy, on 10/12/2007, -0/+2He seems to copy and paste a bit half hazardly...
Forgot to add $ to var2 (many many many times...)
Forgot to DEVIDE in the devision example...
Forgot to Mod in the Modulus example...
Otherwise it looks fine (at a glance) - trghpy, on 10/12/2007, -0/+1He also mispelled his user name.
The H should be a M. - rmaus, on 10/12/2007, -0/+1I hate to abuse the reply, but I think it's important to use a guide that doesn't suck.
http://www.php.net/manual/en/language.operators.php
- lqqkout4elfy, on 10/12/2007, -3/+5Yo, it seems Haroon's tutorials are flawed with typos! This means, you WILL learn the wrong thing if you went to this site!!
- jrepin, on 10/12/2007, -8/+3Next part:
http://digg.com/programming/Decision_Making_Using_IF_ELSE_In_PHP- polymorphist, on 10/12/2007, -1/+5Ooooops...I dugg you up 'cuz I thought you were joking...but I was wrong...
- marcov8, on 10/12/2007, -3/+1nevermind
- bluephoenix, on 10/12/2007, -1/+22does each chapter really need to be dugg?
- JakeX, on 10/12/2007, -0/+1I don't think so :P but I guess people find it very useful.
- lqqkout4elfy, on 10/12/2007, -1/+1Or, the Digg gods found themselves wanting to learn some more PHP.
- MoneyShot, on 10/12/2007, -2/+8This author was already shredded for his inattention to important details and/or lack of expertise with PHP the last time his series was promoted: http://digg.com/programming/PHP_Programming_Basics
Really, there are TONS of PHP tutorials on the 'net. Why is this (poorly written) one getting any attention?- interociter, on 10/12/2007, -0/+0I've got to agree with you. This article, http://digg.com/programming/PHP_Programming_Primer , from a different author seemed better to me for an intro to PHP but hasn't been dugg up to the front page yet
- BradC, on 10/12/2007, -0/+5Lots of typos (too much copy & paste?). It lists subtraction, division and modulus as all the same thing:
$total = $var1 - var2;- tomhung, on 10/12/2007, -1/+2he is retarded.... get your examples straight
- radicaldementia, on 10/12/2007, -0/+3This looks pretty good for anyone who has never programmed before, but for anyone with some programming experience, including people who've never used PHP, it is too simplistic. Most of this stuff, except for syntax, is common to almost all languages.
What I would really like to see in a tutorial (perhaps later parts of this one) are things that PHP programmers really need to pay attention to, things like escaping GPC input, dealing with sessions, OO PHP, handling and encapsulating database connections. Many tutorials mention these, but fail to demonstrate why they are so important. Then you get programmers who don't know these concepts and end up writing insecure, inefficient, and horribly unorganized websites. - GeorgePBurdell, on 10/12/2007, -0/+9I don't think his examples are spot on:
"// Modulus
$var1 = 15;
$var2 = 5;
$total = $var1 - var2;"
This is not an example of modulus. I was thinking about looking at his how-to pages, but now I am definitely not. He can't even cut and paste code correctly. - VenTatsu, on 10/12/2007, -0/+4The author fails to even mention the issue of precedence and direction of association of operators. These details can often confuse new programmers, and trip up veterans when a new language behaves differently and an old one.
- fahrvergnuugen, on 10/12/2007, -0/+10I found this one to be more complete: http://php.net/operators
- vh1`, on 10/12/2007, -0/+4that's the one thing I really liked about PHP, php.net is just about all you need for help.
- lqqkout4elfy, on 10/12/2007, -0/+2http://www.php.net FTW!
- aaroncampbell, on 10/12/2007, -0/+3It seems he touched on arithmetic operators, assignment operators, comparison operators, and logical operators (except xor). He completely skipped bitwise operators, error control operators, execution operators, string operators, type operators, etc.
- shockingbird, on 10/12/2007, -0/+5And smooth operators.
- PrisonerOfPain, on 10/12/2007, -0/+1Same for telephone and machine operators.
- emehrkay, on 10/12/2007, -0/+1bitwise and order??
- rip747, on 10/12/2007, -0/+2buried for lamsness
- kbeeveer46, on 10/12/2007, -0/+1As much as I want to learn PHP, I really hope I don't have to see one of your tutorials on the front page of digg EVERY day...
- echeese, on 10/12/2007, -0/+1Site reminds me of Mozilla.org. Quite a lot now that I compare the two
- dotdan, on 10/12/2007, -1/+2Modulus is pretty simple. Like the author says, it's used to find the remainder. The most common usage is figuring out whether there is or isnt a remainder.
Example..
$i = 1;
while($resultSet) {
if($i % 2 == 0) {
$row = 2;
} else {
$row = 1;
}
$i++;
}
That's how alternating rows are done. If the number can be evenly divided by two, it's an even (alternate) row, otherwise it follows the first pattern.
I can't believe this site keeps getting dugg..- prockcore, on 10/12/2007, -0/+2Man I hate overly verbose code.
$i=0;
while ($resultSet)
{
$row=($i&1)+1;
....
$i++;
}
So much nicer. - PrisonerOfPain, on 10/12/2007, -0/+2if($i & 1) is how alternating rows are done in my book. But hey! Welcome to the "this bitwise ***** is way to hard"-era.
- smhill, on 10/12/2007, -0/+1You don't need two variables to do the work of one. Nor do you need to define it or increment it. just a simple boolean operation.
...
$row=($row==2)?1:2;
...
or if you are writing a style or something in display code all you need is this:
<tr class="<?=$alt=($alt=="one")?"two":"one";?>">
...
- prockcore, on 10/12/2007, -0/+2Man I hate overly verbose code.
- penagate, on 10/12/2007, -0/+3Singularly useless.
- stupidfathead, on 10/12/2007, -0/+1Can you imagine actually paying this fellow to program for you? Most of your money would be spent on him debugging copy and paste errors. It is cool that he is trying to help others, but teaching flawed code is pretty lame. Buried for spreading misinformation.
- heavyal, on 10/12/2007, -0/+1If the guy cant even design a site that is aesthetically pleasing and functional without the ad-crap why would anyone want to rely on his coding methodologies? Personally if I had to maintain such sloppy code I'd sooner shoot myself.
- m3rcenary, on 10/12/2007, -1/+1not sure why this was digged, this is an intro to PHP
- lauridsd, on 10/12/2007, -0/+2The very first thing I skimmed to and it is incorrect:
"Subtraction: it is denoted by minus sign ( - ) and is used to subtract first value from the second e.g 2 - 1 = 1"
Even his own example shows that you are subtracting the SECOND value from the FIRST. (If you were subtracting the first value from the second value in that example, the result would be "-1", which is completely counter-intuitive anyway.)
A nitpick? Perhaps, but technical documentation is useless if it is not both semantically and technically accurate. - kenmantx, on 10/12/2007, -0/+1Buried as inaccurate, the examples are pure *****.
- yogastore, on 06/27/2008, -0/+0http://astore.amazon.com/baby.dry.diapers-20
http://astore.amazon.com/huggies.baby.diapers-20
http://astore.amazon.com/nike.heart.rate.monitor.w ...
http://astore.amazon.com/polar.heart.rate.monitor. ...
http://astore.amazon.com/digital.bathroom.scale-20
http://astore.amazon.com/digital.food.scale-20
http://astore.amazon.com/kitchen.trash.can-20
http://astore.amazon.com/outdoor.trash.can-20
http://astore.amazon.com/digital.pedometer-20
http://astore.amazon.com/omron.digital.pedometer-2 ...
The Digg Toolbar for Firefox lets you Digg, submit content, and keep track of Digg even when you're not on the Digg site. Download the official