john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

php user defined function

php-user-defined-function

<?php
function foo($arg_1, $arg_2, /* ..., */ $arg_n)
{
    echo "Example function.\n";
    return $retval;
}
?>


function takes_array($input)
{
    echo "$input[0] + $input[1] = ", $input[0]+$input[1];
}
?>

pass by reference
function add_some_extra(&$string)
{
    $string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str;    // outputs 'This is a string, and something extra.'

<?php
function recursion($a)
{
    if ($a < 20) {
        echo "$a\n";
        recursion($a + 1);
    }
}
?>

returning multiple values
<?php
function small_numbers()
{
    return array (0, 1, 2);
}
list ($zero, $one, $two) = small_numbers();
?>

  • « php webadmin htpasswd file php
  • php start download with readfile »

Published

Feb 6, 2010

Category

php

~73 words

Tags

  • defined 2
  • function 14
  • php 82
  • user 18