Most PHP function parameters accept multiple data types, including scalar types (integers, floating point numbers, strings, booleans), composite types (arrays, objects), and other types (NULL, resource references). For example, the function myFunction accepts string, integer, and string type parameters and outputs the values passed to these parameters when the function is called.
Acceptable data types for PHP function parameters
Most PHP function parameters can accept multiple data types, the following are The most common data type:
Scalar type:
Composite type:
Other types:
Actual case:
function myFunction($name, $age, $hobby) { echo "姓名:$name <br>"; echo "年龄:$age <br>"; echo "爱好:$hobby <br>"; } $name = "John Doe"; $age = 30; $hobby = "编程"; myFunction($name, $age, $hobby);
Example output:
姓名:John Doe 年龄:30 爱好:编程
This function accepts three parameters: $name
(string), $age
(integer), and $hobby
(string). It outputs the values passed to these parameters.
The above is the detailed content of What data types can PHP function parameters accept?. For more information, please follow other related articles on the PHP Chinese website!