To return an array in PHP, you can simply add the array as the return value in a function. Here's an example:
main.php110 chars8 lines
In the above example, the getArray()
function returns an array [1, 2, 3, 4, 5]
. The returned array is then assigned to the $result
variable, and you can use print_r()
function to display the contents of the array.
Output:
main.php75 chars9 lines
Note: It's important to use print_r()
or var_dump()
to display the array values because echo
or print
will not show the array structure in a human-readable format.
gistlibby LogSnag