|
Feb 20
2012
|
PHP Return ArrayPosted by bohemia in Untagged |
|
PHP Return Array
With PHP, you can return a variable or an array from a function. The example below demonstrates how to return a simple array.<?php
function people(){
$myarray = array('jane','bob','mike','phil');
print_r($myarray);
return $myarray;
}
//The function will make variable called $mytotal which can be returned from the function
$total = people();
echo "<br/><br/>";
//$total is setting the variable equal to the function
//The value $mytotal is returned and is printed below
echo "The array are the people $total[0], $total[1], $total[2] and $total[3].";
?>
function people(){
$myarray = array('jane','bob','mike','phil');
print_r($myarray);
return $myarray;
}
//The function will make variable called $mytotal which can be returned from the function
$total = people();
echo "<br/><br/>";
//$total is setting the variable equal to the function
//The value $mytotal is returned and is printed below
echo "The array are the people $total[0], $total[1], $total[2] and $total[3].";
?>
