PDA

View Full Version : A "must-have" for new PHP programmers


flames
03-02-2005, 05:02 AM
As you know, I had been using php for only a couple of months, and I had faced alot of problems and other challenges. Sometimes it even took me a few hours just to make a php-coded page!
I do not know if any of these easy rules are useful for everyone, but I am quite positive that php beginners should find this quite useful.
************************************************** *********
Common Operators (Comparison)
-=-=-=--=-=-=-=-=-=-=-=-=-=-

Operator

1.== means the equal operator. Used to test if two values are identical.
if($a == $b)
2.!= means the not equal operator. Used to test if two values are different.
if($a != $b)
3.> means the greater than operator (like in math). used to test if the first value is greater than the second value.
if ($a > $b)
4.< means the less than operator. used to test if the first value is smaller than the second value.
if($a < $b)
5.>= means the equal to or the greater operator. Used to test if the first value is greater than or equal to the second value.
if($a >= $b)
6.<= means the less than or equal to operator. used to test if one value is less than or equal to the second value.
if($a <= $b)
7.&& means the "and" operator. used to evaluate multiple conditions where you want all the conditions to be true.
if(($a == $b) && ($c == $d))
8.! means the "not" operator. Used to test if a condition is false.
if(($a == $b) ! ($c == $d))
9.|| means the "or" operator. Used to evaluate multiple conditions where you want any one of the conditions to be true.
if(($a == $b) || ($c == $d))

Ipsquiggle
03-02-2005, 05:52 AM
Your usage of "not" is incorrect. it should read either:
if(!($c == $d)): (same as $c != $d)
or
if(!$a): (boolean, but since you never covered if($a):, its kinda extraneous.)

mck9235
03-02-2005, 10:34 PM
Thanks, that was helpful. :)

Why do you jeep ending the stuff with ':', isn't it a semicolon? :confused:

Magicalneo
03-03-2005, 10:01 AM
what does php=id
php=action

means?

shwaza
03-03-2005, 11:23 AM
Haha, you know, i didn't even know a couple of those :P The one that helped me was || I was actually wondering if there was an OR statement for php :)

Thanks

Killzone-Malone
07-20-2008, 10:05 PM
Thank you this will help me with learning this stuff,

outsider
07-21-2008, 07:14 AM
Besides that, you can also use the words 'and' , 'or' instead of the symbols '&&', '||'

cDizzle
07-21-2008, 07:37 AM
1.== means the equal operator. Used to test if two values are identical.

== does not mean identical to. == means equivalent to.
=== means identical to.
!= means not equivalent
!== means not identical to

Hope nobody got screwed up by mis-information on this one

daman371
07-21-2008, 07:41 AM
cDizzle is correct. A synonym for equivalent of course is equal. Most of the time equal is used, however. Another operator for not equal is <>. I never use this but it's out there.


if ($a <> $b)
{
//do something
}

cDizzle
07-21-2008, 08:04 AM
it isnt really a synonym for equal, because equal would be like $var = anything; which you would read: dollar var (depending on how you say that) equals anything

== really just means equivalent to.

=== identical to is mostly useful when differentiating between false and 0, like strpos(), if the needle is found at the very beginning of the string it will return 0 but its a valid pos so you would do

if( strpos($str, $search) !== false )
{
// do something
}

outsider
07-21-2008, 11:04 AM
Oh! Thats real complex! I didn't know that...