PHP Functions

Create a PHP Function

function is a block of code that can be executed whenever we need it.

Creating PHP functions:

  • All functions start with the word “function()”
  • Name the function – It should be possible to understand what the function does by its name. The name can start with a letter or underscore (not a number)
  • Add a “{” – The function code starts after the opening curly brace
  • Insert the function code
  • Add a “}” – The function is finished by a closing curly brace

function function_name()
{
code to be executed;
}

Example Use a PHP Function

<html>
<body>
<?php
function writedate()
{
$d = date(“Y-m-d”); //today is 2008-04-27
echo “$d”;
}
echo “Hello world!<br />”;
echo “Today is “;
writedate();
?>
</body>
</html>

and output is

Hello world!
Today is 2008-04-27

Leave a comment

7 Comments.

  1. Hey – nice blog, just looking around some blogs, seems a pretty nice platform you are using. I’m currently using WordPress

  2. Hey, maybe this is a bit offf topic but in any case, I have been surfing about your blog and it looks really neat. impassioned about your writing. I am creating a new blog and hard-pressed to make it appear great, and supply excellent articles. I have discovered a lot on your site and I look forward to additional updates and will be back.

  3. Looking after your hearing has to be one of the most significant things you can do. Take it from me, somebody who sufferred hearing damager early on. As a result, I actually like taking care hearing and whilst I do agree with the above-named poster and I really hope I do not get shot down for stating this, but I guess it is important to take all things in moderation.

  4. Multumesc pentru continut interesant..

  5. This is certainly one of the most remarkable blogs I’ve seen. It’s so simple to tune out, but there is really some unparalleled material online, and I think your site is one of the few!

  6. U wilt geld lenen zonder BKR toetsing? De opties hiervoor worden groter, kijk verder en ontdek hoe u wél geld kunt lenen, snel & eenvoudig.

  7. Good topic for making an effective dissertation. . . . . .

Leave a Reply


[ Ctrl + Enter ]