You must understand the parameters of the function (in detail)
The last article introduced you to "Let’s talk about the difference between the return statement and echo (detailed explanation and examples)". This article continues to introduce the parameters of the function to you. Now let’s go and take a look. Look! ! !
Parameters of function (actual parameters and formal parameters):
Formal parameter variables only allocate memory units when called , at the end of the call, the allocated memory unit is released immediately. Therefore, formal parameters are only valid within the function. After the function call ends and returns to the calling function, the formal parameter variable can no longer be used.
Actual parameters can be constants, variables, expressions, functions, etc. No matter what type of quantities the actual parameters are, they must have definite values when making function calls so that these values can be transferred to formal parameters. Therefore, assignment, input, etc. should be used in advance to obtain a certain value for the actual parameters.
The actual parameters and formal parameters should be strictly consistent in number, type, and order, otherwise a "type mismatch" error will occur.
The data transfer that occurs in function calls is one-way. That is, only the value of the actual parameter can be transferred to the formal parameter, but the value of the formal parameter cannot be transferred in the reverse direction to the actual parameter. Therefore, during the function call, the value of the formal parameter changes, but the value of the actual parameter does not change.
Simply put, parameters are divided into two parts: formal parameters and actual parameters:
Formal parameters are formal parameters, used in parentheses when defining functions;
The actual parameter is the actual parameter, used in the parentheses of the calling function;
For example, int F(int i) i is the formal parameter,
The actual parameter is the function call When there are parameters passed by the calling function to the called function, for example:int x=1; a=F(x);Copy after login
x here is the actual parameter. After the function is called, the value of x is passed to the formal parameter. i
Note:
If the function has defined parameters, the corresponding actual parameters must be passed in when calling the function (When the formal parameter has no default value)
If the function also has the default value of the formal parameter and the corresponding actual parameter is passed in, then the passed actual parameter will be the main one (equivalent to For variable assignment, use the value of the actual parameter to assign the value to the formal parameter)
The specific operation takes the code as an example:
<?php /******函数的参数 */ function table (){ $str = '<table border="1" align="center" width="800">'; for ($tr = 0; $tr < 10; $tr ++){ $str .= '<tr>'; for($td = 0; $td < 10; $td ++){ $str .= '<td>'.$tr.$td. '</td>'; } $str .= '</tr>'; } $str .= '</table>'; //返回值 返回一个表格 return $str; } $table = table(); echo $table; ?>
The demonstration results are as follows:
Code analysis:
We use the function function to define a table, and then set the specifications of the table (supplementary: align refers to adjustment, calibration, center: center), and then set Define the for loop, enter the for loop and continue to set the second for loop statement. The specific code is as shown above. At the end, we use return to return the value (the purpose is to determine whether the return statement can return a value successfully and whether it can return a table. ), when we return a table, call the table statement, {$table=table()}, output (table). Overall, we first define a variable (table), connect one (tr tag) in the table, and then connect 10 (td). At this time, the loop ends, and we connect an end flag (/td). At this time, we continue Loop, and so on;
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of You must understand the parameters of the function (in detail). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

New feature of PHP5.4 version: How to use callable type hint parameters to accept callable functions or methods Introduction: PHP5.4 version introduces a very convenient new feature - you can use callable type hint parameters to accept callable functions or methods . This new feature allows functions and methods to directly specify the corresponding callable parameters without additional checks and conversions. In this article, we will introduce the use of callable type hints and provide some code examples,

Product parameters refer to the meaning of product attributes. For example, clothing parameters include brand, material, model, size, style, fabric, applicable group, color, etc.; food parameters include brand, weight, material, health license number, applicable group, color, etc.; home appliance parameters include brand, size, color , place of origin, applicable voltage, signal, interface and power, etc.

During the development process, we may encounter such an error message: PHPWarning: in_array()expectsparameter. This error message will appear when using the in_array() function. It may be caused by incorrect parameter passing of the function. Let’s take a look at the solution to this error message. First, you need to clarify the role of the in_array() function: check whether a value exists in the array. The prototype of this function is: in_a

C++ parameter type safety checking ensures that functions only accept values of expected types through compile-time checks, run-time checks, and static assertions, preventing unexpected behavior and program crashes: Compile-time type checking: The compiler checks type compatibility. Runtime type checking: Use dynamic_cast to check type compatibility, and throw an exception if there is no match. Static assertion: Assert type conditions at compile time.

i9-12900H is a 14-core processor. The architecture and technology used are all new, and the threads are also very high. The overall work is excellent, and some parameters have been improved. It is particularly comprehensive and can bring users Excellent experience. i9-12900H parameter evaluation review: 1. i9-12900H is a 14-core processor, which adopts the q1 architecture and 24576kb process technology, and has been upgraded to 20 threads. 2. The maximum CPU frequency is 1.80! 5.00ghz, which mainly depends on the workload. 3. Compared with the price, it is very suitable. The price-performance ratio is very good, and it is very suitable for some partners who need normal use. i9-12900H parameter evaluation and performance running scores

Hyperbolic functions are defined using hyperbolas instead of circles and are equivalent to ordinary trigonometric functions. It returns the ratio parameter in the hyperbolic sine function from the supplied angle in radians. But do the opposite, or in other words. If we want to calculate an angle from a hyperbolic sine, we need an inverse hyperbolic trigonometric operation like the hyperbolic inverse sine operation. This course will demonstrate how to use the hyperbolic inverse sine (asinh) function in C++ to calculate angles using the hyperbolic sine value in radians. The hyperbolic arcsine operation follows the following formula -$$\mathrm{sinh^{-1}x\:=\:In(x\:+\:\sqrt{x^2\:+\:1})}, Where\:In\:is\:natural logarithm\:(log_e\:k)

Although large-scale language models (LLM) have strong performance, the number of parameters can easily reach hundreds of billions, and the demand for computing equipment and memory is so large that ordinary companies cannot afford it. Quantization is a common compression operation that sacrifices some model performance in exchange for faster inference speed and less memory requirements by reducing the accuracy of model weights (such as 32 bit to 8 bit). But for LLMs with more than 100 billion parameters, existing compression methods cannot maintain the accuracy of the model, nor can they run efficiently on hardware. Recently, researchers from MIT and NVIDIA jointly proposed a general-purpose post-training quantization (GPQ).

Reference parameters in C++ functions (essentially variable aliases, modifying the reference modifies the original variable) and pointer parameters (storing the memory address of the original variable, modifying the variable by dereferencing the pointer) have different usages when passing and modifying variables. Reference parameters are often used to modify original variables (especially large structures) to avoid copy overhead when passed to constructors or assignment operators. Pointer parameters are used to flexibly point to memory locations, implement dynamic data structures, or pass null pointers to represent optional parameters.
