PHP Function - How To Specify Argument Default Values
Interview Question Database For Software Developers
|
|
| How To Specify Argument Default Values | | How To Specify Argument Default Values? - PHP Script Tips - Creating Your Own Functions | | By: FYIcenter.com | If you want to allow the caller to skip an argument when calling
a function, you can define the argument with a default value when defining
the function. Adding a default value to an argument can be done like this
"function name($arg=expression){}.
Here is a PHP script on how to specify default values to arguments:
<?php
function printKey($key="download") {
print("PHP $key\n");
}
printKey();
printKey("hosting");
print("\n");
?>
This script will print:
PHP download
PHP hosting
| | ID: 341 | Rank: 1077 | Votes: 0 | Views: 33 | Submitted: 20070425 |
1078 :-) | | What Is a Cookie | | What Is a Cookie? - PHP Script Tips - Understanding and Managing Cookies... | | Submitted: 20070425 |
|
Copyright © 2009 FYIcenter.com
All rights in the contents of this Website are reserved by the individual author.
No part of the contents may be reproduced in any form without author's permission.
|
|
|