How to Create Function in PHP

How to create function in PHP? lot of newbies in PHP are searching the answer of this question. Functions has key roll in PHP web development language. Any of the PHP program is incomplete without functions. In other words we can say without functions no any program can be written in PHP.

function in php
Create function in php

Create Function in PHP:

I will show you in step by step guide, just read this post till to end, first start PHP script with PHP opening tag.

<?php

Now create function with keyword function and assign a name to the function you want to create. I have given it a name hello.

function hello()

Now create some coding for function hello to execute, but remember that you must write these coding in curly brackets.

{
echo "Hello world!";
}

Now call function hello to execute the coding and close PHP script with closing tag of PHP. But remember the most important thing that you don’t need to write is echo statement as we write to print variable.

hello(); 
?>

In above sections of code I have created a user define function for you. It’s very easy to understand. In this example I have written “hello Word!” sentence with echo statement only as coding for function hello to execute. You may write what ever code you want to execute with function hello.

In this way you can create functions in PHP, it’s the basic function in PHP. You can say the simplest form of function too. PHP has lot of builtin functions too. You don’t need to create them, just need to understand. I will tell you about builtin functions of PHP.

Dear friends if you don’t know how to declare variables in PHP, don’t worry, I have already written a post on this topic too, just you can visit this link How to Declare Variable in PHP

If you want to start a video sharing website in php, I recommend you these scripts to you, I hope you will enjoy. Best 10 PHP Scripts to Start Video Sharing Site

Leave a Reply

Your email address will not be published. Required fields are marked *