Page 1 of 1

PHP markup

Posted: Mon Apr 14, 2008 6:23 pm
by stefharley
I have great dificaulty remembering when i should use (brackets) when i should use {curly brackets} when i should use "quotation marks", 'quotation marks' [square brackets] etc.
I cant seem to find any documentation that explains just this. i would find it so much easier if i had reference!!

Forgive me if this is already on this forum, i just cant find it if it is!

thnx in advance if anyone can help

Stef :banghead:

Re: PHP markup

Posted: Mon Apr 14, 2008 6:31 pm
by Chris Corbyn

Re: PHP markup

Posted: Mon Apr 14, 2008 6:48 pm
by s.dot
It's pretty easy, really.

Expressions go in brackets. Expressions are ($var), ($var == 1), ($var < 3) etc.
Code blocks require curly brackets { }.. so a simple if/else would look like this

if ($var < 3)
{
//do something here
} else
{
//do something else here
}

Strings can use either " or '

echo 'My name is Scott';
echo "My name is Scott";

However, variables can be interpreted inside double quotes only

$name = 'Scott';
echo "My name is $name";

However, you can use single quotes and concatenation

$name = 'Scott';
echo 'My name is ' . $name;

Array indexes go in brackets []

$_POST['username']
$_POST['password']
$MyArray[3]

The indexes can be treated the same as strings

$_POST["$var"]
$_POST['var' . $var]

Re: PHP markup

Posted: Mon Apr 14, 2008 8:14 pm
by stefharley
Thnx scottayy

Just what i was looking for!

I can smile again!