Home Tutorial Php PHP Variables Default Value

 
 

Share on Google+Share on Google+
PHP Variables Default Value
Posted on: January 11, 2010 at 12:00 AM
Advertisement
In this tutorial we will learn how to set default value in PHP variables or Functions. If there is no value in the variable passed to the function call than only the default value is used by the function.

PHP Variables Default Value


In this tutorial we will learn how to set default value in PHP variables or Functions. If there is no value in the variable passed to the function call than only the default value is used by the function. Here, we also learned how to pass information to the function through function call. For example :

<?php function Welcome($current_visitor)

{

    echo "Hello ".$current_visitor;

}

Welcome("Suraj");

?>


The output of the above example is : Hello Suraj.
In the above example we define function Welcome which has only one variable or you can say argument variable that is $current_visitor. In the function call we passed the variable value called Suraj. If there is no value passed in the function call the only thing will shown in the screen is Hello. Let see the example where we haven't passed any value in the variable argument.

 

<?php

function Welcome($visitor="People!")

{

    echo "Hello ". $visitor;

}

Welcome();

?>


You can notice that the default value is set by assigning the value to the argument variable within the parenthesis where the function defined . This value will be used by everyone, if no other value is passed through function call. You can see in the function call the parenthesis are blank, it means no other value have been passed in the function.

Advertisement

Related Tags for PHP Variables Default Value:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 11, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com