Ladoo, think of it like this (it's how i got used to it from VB)
if VB you MAY put () around your IF. (wasted code but no real harm against it)
#1 IF example, in VB:
is the same asCode:IF A > B THEN msgbox("yes") END IF
#2 IF example in (still in VB):
in php you MUST use () around your condition.Code:IF (A > B) THEN msgbox("yes") END IF
and in php you replace THEN with a { symbol and END IF with a } symbol
so looking at example 2 again:
#2 IF example in VB:
#2 IF example translated to php:Code:IF (A > B) THEN msgbox("yes") END IF
once you get that down, the rest is easy.Code:IF (A > B) { msgbox("yes"); }
and here it is:
instead of saying
you have to use TWO == symbols.Code:IF (A = B) THEN do this END IF
the reason is simple:Code:IF (A == B) { do this }
php is stupid.
in VB it knows that "Hey! i'm doing an IF because i saw the word IF!"
but php it says "wait, what was i doing after i read that word IF?? OH! TWO == symbols! that means i'm doing an IF still!"
vb vs php:
Code:VB | PHP ---------------------------------------------- IF ( condition ) THEN | IF (condition) { ELSE | } ELSE { END IF | } IF ( A > B) THEN | IF (A > B) { IF ( A < B) THEN | IF (A < B) { IF ( A => B) THEN | IF (A >= B){...... (ALWAYS the > or < comes before the = IF ( A NOT B) THEN | IF (A != B) { IF ( A <> B) THEN | IF (A != B) { IF ( A = B) THEN | IF (A == B) { IF (A <> B AND C = D) THEN | IF ((A != B) AND (C == D)) { VB: IF ( Cow > Moon AND Time = NIGHT) THEN Print "Cow Jumped Over The Moon At Night" ELSE Print "Something didn't go as planned and the cow got hurt" END IF PHP: IF ( (Cow > Moon) AND (Time == NIGHT)) { echo "Cow Jumped Over The Moon At Night"; } ELSE { echo "Something didn't go as planned and the cow got hurt"; }
Now there are 3 things that still get me. they just take getting used to.
First, VB is smart. It knows when it's done with a command.
but after every PHP command you need to type that annoying semicolon. ;
because, like i said, php just isn't that bright.
Second: the == gets me very often.
in PHP if you put one = instead of == then it will say IF ... OH, this = that so i must do { this }
so many times i stared at a php IF THEN and simply couldn't see that i had one = instead of two == causing all of my problems.
and last, remember the variable names are case sensitive.
$Hello = "Hi"
$hello = "bye"
echo "i said $Hello then i said $hello.";
output is:
i said Hi then i said bye.




Reply With Quote