Functions


Returning Values

Values are returned by using the optional return statement. In general, only one value can be returned except for array type. You should use array type if you want to return multiple values.

<?php

function func()
{
  $var1 = 1;
  $var2 = 2;
  $var3 = 3;
  $arr = array($var1, $var2, $var3);
  return $arr;
}

$arr = func();
printf("%d, %d, %d\r\n", $arr[0], $arr[1], $arr[2]);

?>
[result]  
1, 2, 3

※ PHPoC returns not NULL but 0 if there is no return statement or the argument of return statement is omitted.

※ PHPoC does not support returning a reference from a function.