Just a quick question

#1

Even though I’ve been using php for a few months now, I have a quick question (that’s why I’ve posted in the beginners section).

Let’s say you had a custom function.

function name_me_plz ($var_1, $var_2, $var_3 = '') {
    // Do stuff here
}

What does $var_3 do? Does it set it to the value I’ve put (which is nothing)? If so, is that considered being null?

#2

yes and no.

it will be set to ‘’ in you call the function with 2 arguments
name_me_plz (‘a’,‘b’,‘c’)
$var3=‘c’
name_me_plz (‘a’,‘b’)
$var3=’’

but an empty string is not null

#3

Right. So, just one more thing. I can easily override it, right? Something like this?

function name_me_plz($var_1, $var_2, $var_3 = '') {
    // Blah
    $var_3 = $_POST['var_3'];
    // Do other stuff here
}
#4

Yes, you can.
But I think that this will be better:
[php]
function name_me_plz($var_1, $var_2, $var_3 = ‘’) {
// Blah
$var_3 = (isset($_POST[‘var_3’]) ? $_POST[‘var_3’] : ‘’) ;
// Do other stuff here
}
[/php]

#5

Basically what it does is give $var3 a default value, and makes it optional. It keeps the PHP engine from screaming bloody hell when you only provide two parameters when callilng the function :slight_smile: