PHP functions can return multiple types of data, including Boolean values, integers, floating point numbers, strings, arrays, objects and null values.
Common types of PHP function return types
PHP functions can return various types of data, including:
true
or false
Practical case
The following code shows A function that returns a Boolean value indicating whether the user is an adult based on a given age:
function isAdult($age) { return $age >= 18; } // 使用函数 if (isAdult(21)) { echo "用户已成年"; } else { echo "用户未成年"; }
In this example, the isAdult()
function returns a Boolean value, true
means the user is an adult, false
means the user is not an adult.
The above is the detailed content of What are the common return value types of PHP functions?. For more information, please follow other related articles on the PHP Chinese website!