Dear All
If I have a function return_strings($itemID), can I make it return an array of values? For example, could I do this -
$string1 = return_strings(5)[1];
$string2 = return_strings(5)[2];
$string3 = return_strings(5)[3];
It doesn't seem intuitively that this would be the case - in which case, is there any other way of doing this?
Many thanks
Mark
Returning arrays from a function in PHP
Moderator: General Moderators
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
You can have functions return an array although I would try to create the array with a meaningful index:
using
would call the function 3 times.
Code: Select all
function getArray() {
$retval=array("name"=>"CoderGoblin","desc","PHP Coder");
return $retval;
}
// Get result of array
$my_array=getArray();
// process the individual columns
$my_name=$my_arrayї'name'];
$my_desc=$my_arrayї'desc'];Code: Select all
$string1 = return_strings(5)ї1];
$string2 = return_strings(5)ї2];
$string3 = return_strings(5)ї3];