return function php code example
Example 1: function php
function functionName() {
//code to be executed;
}
Example 2: return two variables php
function getXYZ()
{
return array(4,5,6);
}
list($x,$y,$z) = getXYZ();
// Afterwards: $x == 4 && $y == 5 && $z == 6
// (This will hold for all samples unless otherwise noted)
Example 3: php return array
<?php
function data() {
$out[0] = "abc";
$out[1] = "def";
$out[2] = "ghi";
return $out;
}
$data = data();
foreach($data as $items){
echo $items;
}