Пример #1
0

<?php 
function say_hello_to($word)
{
    echo "Hello {$word}!<br />";
}
// Passing in a variable with a different name
$name = "SSL Developers @ Full Sail";
say_hello_to($name);
?>
<br /><br />
<?php 
function better_hello($greeting, $target, $punct)
{
    echo $greeting . " " . $target . $punct . "<br />";
}
better_hello("Hello", $name, "!");
better_hello("Greetings", $name, "!!!");
better_hello("Goodbye", $name, null);
?>


	





</body>
</html>
Пример #2
0
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html lang="en">
  <head>
    <title>Functions: Arguments</title>
  </head>
  <body>

    <?php 
function say_hello_to($word)
{
    echo "Hello {$word}!<br />";
}
$name = "John Doe";
say_hello_to($name);
?>
    
    <?php 
function better_hello($greeting, $target, $punct)
{
    echo $greeting . " " . $target . $punct . "<br />";
}
better_hello("Hello", $name, "!");
better_hello("Greetings", $name, "!!!");
better_hello("Greetings", $name, null);
?>

  </body>
</html>
            return 'Horse';
        case 7:
            return 'Goat';
        case 8:
            return 'Monkey';
        case 9:
            return 'Rooster';
        case 10:
            return 'Dog';
        case 11:
            return 'Pig';
    }
}
$zodiac = chinese_zodiac(2013);
echo "2013 is the year of the {$zodiac}.<br />";
echo "2027 is the year of the " . chinese_zodiac(2027) . ".<br />";
?>
    <br />
    
    <?php 
function better_hello($greeting, $target, $punct)
{
    return $greeting . " " . $target . $punct . "<br />";
}
echo better_hello("Hello", "John Doe", "!");
?>
    

  </body>
</html>
Пример #4
0
        case 6:
            return 'Horse';
        case 7:
            return 'Goat';
        case 8:
            return 'Monkey';
        case 9:
            return 'Rooster';
        case 10:
            return 'Dog';
        case 11:
            return 'Pig';
    }
}
// grab the return value
$zodiac = chinese_zodiac(2013);
echo "2013 is the year of the {$zodiac}.<br />";
echo "2027 is the year of the " . chinese_zodiac(2027) . ".<br />";
?>
<br /><br /><br />
<?php 
function better_hello($greeting, $target, $punct)
{
    return $greeting . " " . $target . $punct . "<br />";
}
echo better_hello("Hello", "~Jana Nash-Siegle", "!");
//You can only have one return per function
?>

</body>
</html>