Page 1 of 1

some code explaining

Posted: Thu Jan 01, 2009 8:00 pm
by bugpanye
i've been doing php for a few months now.. so far its been easy to use,
however i stumbled across a page which has a code like this

Code: Select all

$path = !empty($_REQUEST['path']) ? $_REQUEST['path'] : dirname(__FILE__);
so i have this piece of code right, i'm guessing the ? is suppose to mean if satisfy the previous condition
however i'm pretty loss at that ":"

can anyone explain to me what does the ":" mean?

and lastly.. can you also point me to a page where i can learn all these "special characters" cause i dont know the keyword to search for thanks!

Re: some code explaining

Posted: Thu Jan 01, 2009 8:10 pm
by Christopher
This:

Code: Select all

$path = !empty($_REQUEST['path']) ? $_REQUEST['path'] : dirname(__FILE__);
Is the same as this:

Code: Select all

if (!empty($_REQUEST['path'])) {
    $path = $_REQUEST['path'];
} else {
    $path = dirname(__FILE__);
}

Re: some code explaining

Posted: Thu Jan 01, 2009 8:27 pm
by requinix
bugpanye wrote:and lastly.. can you also point me to a page where i can learn all these "special characters" cause i dont know the keyword to search for thanks!
There isn't really a list of symbols (that I know of) but the operator precedence page comes really close.

Re: some code explaining

Posted: Thu Jan 01, 2009 8:33 pm
by josh