Monday, April 18, 2011

PHP Functions with optional arguments - example

function foo($arg1 = '', $arg2 = '') {

echo "text1: $arg1\n";
echo "text2: $arg2\n";

}

foo('hello','world');
/* prints:
text1: hello
text2: world
*/

foo();
/* prints:
text1:
text2:
*/

1 comment: