PHP functions

on Thursday, November 8, 2012

Functions

The beautiful of PHP is the functions of PHP. Come to the types of functions ,
Types of PHP functions, we dividing here

1)User Defined functions
2)PHP In-built Functions.
                a) frequently used functions
                b) less-frequently used functions

1)User Defined Functions
  You can defined your function according to your use

Syntax:
// without passing argument
function  myfunction()
{
echo “hello , I am in function without arguments”;
}
myfunction();     // calling the function
Outut :
Hello , I am in function without arguments

// function with argument passing
function myfunction($var)
{
return  “hello ”.$var. “ Welcome in function with arguments“;
}
myfunction(“softfive”);  // Calling

You can call by following methods-
i.                     myfunction(“softfive”);
ii.                   myfunction($var=”softfive”);
iii.                  myfunction($var); // pass the value of $var 


2)PHP In-built Functions.

                a) frequently used functions
                b) less-frequently used functions

a) frequently used functions

$var=”hello”;
strtolower($var);  // output “hello” (used for the lower case letters)
strtoupper($var);  // output “HELLO” (used for the upper case letters)
md5($var);   //  to find hash
md5_file($file);  // to file the hash of content of a file
sha1($var);  // to find sha
substr($var,0,3);   //output “hel”
strlen($var);   // calculates the length of a string
trim(“    hello”);   //  output “hello” (reduces white spaces)
str_replace(“ “,”-“,”hello world”);   // output “hello-world”
strcmp(“hello”,”hello”);   // returns true
ucwords($var);  // output   “Hello”
date(“Y-m-d”);                  //  returns the date
date(“Y-m-d  H:i:s”);       // returns the timestamp

b)less-frequently used functions

print_r($array); // prints the array value (mostly used for debugging purpose)
strrev($var);   //  output “olleh”
print      // to print
echo    // to print
require(//file path);          // to include a file
require_once(//file path);            // to include a file once
include(//file path);        (Note include gives warning where as require gives error)

there are so many function that are used lessely or rarely.