PHP: Function Assignment parameter default initial value

Source: Internet
Author: User

Default parameters for functions

When you are allowed to define a function, specify the default value for the parameter, such as:

function Js_location ($url, $alert = ', $top = ') {
if ($alert = = "&& $top = =") {
Header ("Location: $url");
Exit
}

Echo ' <script language= ' JavaScript > ';
if ($alert) {
echo ' Alert ('. Js_contents_code ($alert). ' \‘);‘;
}
echo "window{$top}.location= ' $url ';";
Echo ' </script> ';
Exit
}

At this point, the js_location function parameter $alert, $top specify the default value, you can not pass, but the URL must be passed. Many of the previous parameters of a system function are mandatory, followed by an option, defined in such a way as the test function, such as printf (), mysql_query (), and so on.

PHP: Function Assignment parameter default initial value

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.