How do I understand the parameters in a user-defined function?

Source: Internet
Author: User
How to understand the parameters in a custom function? below is a piece of code in a class: static & nbsp; function & nbsp; start (PDO & nbsp; $ pdo) {self :: init ($ pdo); session_set_save_handler (array (_ CLASS __, open), array (_ CLASS __, close user-defined functions)
Below is a piece of code in a class
static function start(PDO $pdo){
self::init($pdo);
session_set_save_handler(
array(__CLASS__,"open"),
array(__CLASS__,"close"),
array(__CLASS__,"read"),
array(__CLASS__,"write"),
array(__CLASS__,"destroy"),
array(__CLASS__,"gc")
);

session_start();
}

The PDO in this function is used as the form parameter, which is confusing because I understand that the function is used to pass the parameter and return the result of the passed value. how can this string be passed?

Share: More


------ Solution --------------------
There are three types of parameters: value transfer, reference transfer, and default parameter transfer.
(1) value transfer
Function sum ($ a, $ B)
{
Echo $ a + $ B;
}
Sum (); // start to call this function
?>
(2) transfer a reference

$ MyNum = 100;
Function Valuechange ($ number)
{
$ Number = $ number + 1;
Echo $ number ."
";
}
Valuechange (& $ myNum );
Echo $ myNum;
?>
Result: 101,101
(3) passing default parameters
Function holobby ($ style = "sports ")
{
Return "I like $ style
";
}
Echo holobby ();
Echo holobby ("singing ");
?>
Result: I like sports.
I like singing.

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.