php function return value can be an array. In the php function, the return statement is used to return the running result of the function, but the return statement can only return one parameter, that is, it can only return one value, and cannot return multiple values at one time; if you want to return multiple values, you need to use it in the function Define an array, store the return value in the array and return it, that is, return a value of array type, the syntax is "return $arr;".
The operating environment of this tutorial: windows7 system, PHP version 8.1, DELL G3 computer
The return value of the php function can be an array .
A function is a collection of functions that can implement certain specific functions or operations. It makes no sense to keep the result after the function is run inside the function, so we need to return the result of the function to the place where the function is called.
PHP provides the return statement to return the running result of the function. Its syntax format is as follows:
return 返回值;
Among them, the "return value" is an optional parameter, which can be a specific value or Expression can also be empty. The "return value" and the return keyword need to be separated by a space.
Note: The return statement can only return one parameter, that is, it can only return one value, and cannot return multiple values at one time. If you want to return multiple values, you need to define an array in the function, store the return value in the array and return it, that is, return an array type value.
Example:
<?php header("content-type:text/html;charset=utf-8"); function demo(){ $arr = array( "id"=>1, "name"=>"李华", "age"=>23, ); return $arr; } $arr = demo(); var_dump($arr); ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of Can the return value of a php function be an array?. For more information, please follow other related articles on the PHP Chinese website!