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

13 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. . . . . .

  8. You really make it seem so easy with your presentation but I find this topic to be really something which I think I would never understand. It seems too complicated and very broad for me. I am looking forward for your next post.

  9. I saw this blog through Facebook (my friend posted it). After reading the article, I clicked “Like” and also reshared it myseld.

  10. I am not really sure if best practices have emerged around things like that, but I am sure that your great job is clearly identified. I was wondering if you offer any subscription to your RSS feeds as I would be very interested.

  11. I’m choice the relaunched internet site, Putting a blog site would be a great idea too! I look ahead to discovering how your website changes, oh, as well as it as being an starting point within my on a daily basis function.

Leave a Reply


[ Ctrl + Enter ]