Functions in PHP


Functions are case in-sensitive. Function once can be declare con’t be re-declare in the program

The real power of PHP comes from its functions.

In PHP, there are more than 700 built-in functions

To keep the script from being executed when the page loads, you can put it into a function.

A function will be executed by a call to the function.

You may call a function from anywhere within a page.

  • Give the function a name that reflects what the function does
  • The function name can start with a letter or underscore (not a number)

Syntax: –

function function name (arg)



Return value


There are mainly 8 kinds of functions in php


A function which is enclose inside condition is considered as conditional function




function test(){

echo “I am a Conditional Function <br>”;





When a function name is told

In variable. Variable can be used for excuting the function in a place of function name

Ex: -variables.php


function test(){           echo “I am a Variable Function <br>”;      }


$a = ‘test’;

echo $a;echo ‘<br>’;




Function is define inside another function is called as function-function

Ex: -function’s function.php


Function parent f(){

echo “iam write the function function<br>”;



function child F()

{ echo “I need some one to open parent file for me to excute<br>”;   }

}  }

Parent F();

Child F();

Parent F()’



Function can be defined with one (or) more arguments. It an arguments is not passed through is define its creates warning in the program

Ex: –


function test($x,$y){

echo ‘The Value of $x = ‘,$x,'<br>’;

echo ‘The Value of $y = ‘,$y,'<br>’;








A function at the time of a declaration if argument are assign with some values they will be treated as optional (or) default argument value and they can be passed with value (or) can left without passing the value. Works at the side default argument must be passing last in the program at the argument list

Ex: –


function test($x=10,$y=20){ echo ‘The Value of $x = ‘,$x,'<br>’;

echo ‘The Value of $y = ‘,$y,'<br>’;       }

test(100,200);              test(‘Raj’,’Kiran’);             test();



A function can be define with argument (or) that the defined arguments they are still acknowledge inside the function using various pre-defined function

i) func_num_args(): – return the total number of arguments which are passed in the function

ii) func_get_args(): – return the array with all the argument with the function

iii) func_get_args(position): – return the argument value at the specified position

Ex: –


function test(){

echo “<h1>Overloaded Concept</h1>”;

echo ‘The Overloaded Length = ‘,func_num_args(),'<br>’;


echo ‘<hr>’;


echo ‘Index at : ‘,$i,’ – ‘,func_get_arg($i),'<br>’;


echo ‘<hr><h1>For Each Method</h1>’;

$y = func_get_args();

foreach($y as $k=>$v){          echo “$k => $v<br>”;       }       }      test(10,20,’Rajesh’);


Return key-word can be stop the execution of the function.return key-word can optionally followed with a value which is return variable.whenever a function is a valid another one value con’t be passed after the return statement multiple value con’t be club as array (or) object and con’t be return wherever a function is called

Ex: –


function test(){  echo “This is Return Information<br>”;       //return 10;

echo “I am second info<br>”;     return = 82;

echo “I am second info<br>”;             }


$y = test();

echo $y;       //echo $y;

8. i) arguments passed by value:-

When an arguments pass by value any change for the value inside the function owned be reflected in the variable outside the function

ii) Arguments passed by reference: – when an argument pass by resource and change for the inside with be refer to the variable outside the function

Ex: –

<?php     function test($x,&$y){

$x +=2;   $y +=10; //  $y = $y+10;

echo ‘The Value of $x = ‘,$x,'<br>’;

echo ‘The Value of $y = ‘,$y,'<br>’;


$a = 5;   $b = 10;

echo ‘$a = ‘,$a,'<br>’;//5

echo ‘$b = ‘,$b,'<br>’;//10


echo ‘$a = ‘,$a,'<br>’;//5

echo ‘$b = ‘,$b,'<br>’;//10  ?>

Built-in functions: – Math functions: –   Ex: – 

<?php     echo ‘Math Pi Value = ‘,M_PI,'<br>’;

echo ‘Math Pi Value = ‘,M_PI_2,'<br>’;

echo ‘Math Pi Value = ‘,M_PI_4,'<br>’;

echo ‘Eulers Constant = ‘,M_E,'<br>’;

echo ‘SQRT 2 = ‘,M_SQRT2,'<br>’;

echo ‘SQRT 2 = ‘,M_SQRT1_2,'<br>’;

echo ‘Log of 2 = ‘,log(2),'<br>’;

echo ‘Log base 10 of 2 = ‘,log10(2),'<br>’;

echo ‘Absolute Value = ‘,abs(-9),'<br>’;

echo ‘Exponent of 1 = ‘,exp(2),'<br>’;

echo ‘pi() = ‘,pi(),'<br>’;

echo ‘ceil value = ‘,ceil(2.1111),'<br>’;

echo ‘Floor Value = ‘,floor(2.9999),'<br>’;

echo ’round = ‘,round(2.51458),'<br>’;

echo ’round = ‘,round(2.51558,2),'<br>’;

echo ‘rad2deg(M_PI) = ‘,rad2deg(M_PI),'<br>’;

echo ‘rad2deg(M_PI) = ‘,rad2deg(M_PI_2),'<br>’;

echo ‘rad2deg(M_PI) = ‘,rad2deg(M_PI_4),'<br>’;

echo ‘deg2rad = ‘,deg2rad(180),'<br>’;

echo ‘sin 90 = ‘,sin(M_PI_2),'<br>’;

echo ‘tan 45 = ‘,tan(M_PI_4),'<br>’;

echo ‘hypot value = ‘,hypot(3,4),'<br>’;

echo ‘rand(min,max) = ‘,rand(100,1000),'<br>’;

echo ‘min value = ‘,min(10,20,30),'<br>’;

echo ‘max Value = ‘,max(2.999,2.998),'<br>’;           ?>


Date: – date is the pre-defined constant in php. It will generate current date according to the no of arguments pass

Mktime: – which can have arguments (hr, min, sec, month, day, year) unique time stamp

Check date(): – let us known the validate in a year

j —>represents day of the month without leading zeros

l —->view letter represents of the day of the way

L —> whether it’s a leap year (or) not

W —> week number of year weeks starts from Monday

w —-> numerical represents of day of the way 0 for Monday through 6 for Saturday

S —> English original safix for the day of the month two character ex: -st ,nd, rd,th

F —-> a full representation of the month such as January (or) March

M —> short representation of the month such as jan (or) mar

m —> numerical representation of the month with leading zero’s means 0-12

n —> numerical representation of month without zero’s which is 1-12

d —> number of days given in a month  28 (or) 31

y —> two digits representation of a year

Y —> it is representation of the full year

Time: –no of milliseconds sec right from unique time stamp

a—> lowercase ante meridiem and post meridiem

A—> uppercase ante meridiem and post meridiem

B—> swatch internet time

g—>12- hours format of an hour without leading zeros

G—> 24- hour format of an hour without leading zeros

h—> 12- hours format of an hour with leading zeros

H—>24- hours format of an hour with leading zeros

i—> minutes with leading zero’s

s—> seconds with leading zero’s

u—> microseconds (added in php 5.2.2)

Ex: –


echo ‘Time zone set to  : ‘,@date_default_timezone_get(),'<br>’;


echo ‘Time zone set to  : ‘,@date_default_timezone_get(),'<br>’;

echo ‘Today Date : ‘,@date(“M-dS-Y, h:i:s a”),'<br><hr>’;


echo ‘Time zone set to  : ‘,@date_default_timezone_get(),'<br>’;

echo ‘Today Date : ‘,@date(“M-dS-Y, h:i:s a”),'<br><hr>’;


echo ‘Time zone set to  : ‘,@date_default_timezone_get(),'<br>’;

echo ‘Today Date : ‘,@date(“M-dS-Y, h:i:s A”),'<br><hr>’;


echo ‘<hr>No of milliseconds from Unix time Constant ‘,time(),'<br>’;

echo ‘<hr>Feature Date & time <br>’;

echo ‘Event is on : ‘,(date(“M-dS-Y, h:i:s a”,mktime(7,9,52,8,23,2012))),'<br><hr>’;

echo date(‘Y’);?>




$a = array(10,20,30);

function r($arr,$func=”){

if(!empty($func)){echo “<h2 align=’center’><u>$func</u></h2>”;  }

foreach($arr as $k=>$v){  echo “$k = $v<br>”; }

echo ‘<hr>’;     }

echo ‘Array count = ‘,count($a),'<br>’;

echo ‘Size of = ‘,sizeof($a),'<br>’;

echo ‘Sum of Array = ‘,array_sum($a),'<br>’;

echo ‘Product of Array = ‘,array_product($a),'<br>’;

$a = array(‘Name’=>’Rajesh’,’Age’=>30,’Status’=>’Active’,’Email’=>’Raj@gmail.com’,’Gender’=>’Male’);

r($a,’Normal Array’);

$b = array_change_key_case($a,CASE_UPPER);

r($b,’Upper Case’);

$b = array_change_key_case($a,CASE_LOWER);

r($b,’Lower Case’);

$b = array_flip($a);

r($b,’Array Flip’);

$b = array_change_key_case(array_flip($a),CASE_UPPER);

r($b,’Array Flip  Values’);

$a = array(‘Doctor’,’Fruit’,’Software’);

$b = array(‘Patient’,’Orange’,’PHP’);

r(array_combine($a,$b),’Array Combine’);

$a = array(‘Name’=>’Rajesh’,’Age’=>30,’Status’=>’Active’,’Email’=>’Raj@gmail.com’,’Gender’=>’Male’);

echo ‘<h2 align=”center”>Array Chunk</h2>’;

$b = array_chunk($a,3);

echo ‘<pre>’;


echo ‘</pre>’;

$a = array(10,20,30);

$b = array(10,20,40,50);

r(array_merge($a,$b),’Array Merge’);

r(array_intersect($a,$b),’Array Intersect’);

r(array_diff($a,$b),’Array Diff’);

$a = array(‘raj@gmail.com’,’amith@gmail.com’,’rohan@gmail.com’,’sumit@gmail.com’,’raj@gmail.com’);

r(array_unique($a),’Array Unique’);

r(array_reverse($a),’Array Reverse’);

$a = array(10,20,30);


r($a,’Unshift Method’);


r($a,’shift Method’);


r($a,’Push Method’);


r($a,’Pop Method’);

$ns = $ss = $as = $ks = array(‘Name’=>’Rajesh’,’Age’=>30,’Status’=>’Active’,’Email’=>’Raj@gmail.com’,’Gender’=>’Male’);

r($ns,’Normal Array’);

sort($ss);           r($ss,’Sorted Array’);

rsort($ss);          r($ss,’Reverse Sort Array’);

asort($as);         r($as,’Associative Sort Array’);

arsort($as);        r($as,’Associative Reverse Sort Array’);

ksort($ks);         r($ks,’Key Sort Method’);

krsort($ks);       r($ks,’Key Sort Reverse Method’);

echo “<h2 align=’center’>array_key_exists , array_search , in_array</h2>”;

$a = array(‘Name’=>’Rajesh’,’Age’=>30,’Status’=>’Active’,’Email’=>’Raj@gmail.com’,’Gender’=>’Male’);

echo ‘Do i have Email Feild : ‘,var_dump(array_key_exists(‘Gender’,$a)),'<br>’;

echo ‘Do we have Value with some : ‘,var_dump(array_search(30,$a)),'<br>’;

echo ‘Do we have Value with some : ‘,var_dump(in_array(‘Male’,$a)),'<br>’;

$a = array(‘Name’=>’Rajesh’,’Age’=>30,’Status’=>’Active’,’Email’=>’Raj@gmail.com’,’Gender’=>’Male’);

r(array_keys($a),’Array Keys Calling’);

r(array_values($a),’Array Value Calling’);

$str = ‘Hey i am from India & my name is Praveen’;

$b = explode(” “,$str);

//print_r($b);echo ‘<br>’;

echo ‘The Length of your total Words = ‘,count($b),'<br><hr>’;


echo ‘The index at ‘,$i,’ = ‘,$b[$i],'<br>’;


$a = array(‘raj@gmail.com’,’amith@gmail.com’,’raju@gmail.com’,’suresh@gmail.com’,’raj@gmail.com’,’amith@gmail.com’,’raju@gmail.com’,’suresh@gmail.com’);


$b = implode(‘,’,$a);    <br><br>

To : <input type=’text’ name=’name’ value='<?php echo $b;?>’ size=’60’/> <hr>


$a = array(‘born’,’child’,’teen’,’father’,’dead’);

r($a,’Normal Array’);

echo ‘The Present Pointer is at : ‘,current($a),'<br>And the Key is at ‘,key($a),'<br>’;

echo ‘Next : ‘,next($a),'<br>’;

echo ‘The Present Pointer is at : ‘,current($a),'<br>And the Key is at ‘,key($a),'<br>’;

echo ‘Previous location : ‘,prev($a),'<br>’;

echo ‘The Present Pointer is at : ‘,current($a),'<br>And the Key is at ‘,key($a),'<br>’;

echo ‘End Value : ‘,end($a),'<br>’;

echo ‘The Present Pointer is at : ‘,current($a),'<br>And the Key is at ‘,key($a),'<br>’;

echo ‘The Present Pointer is at : ‘,current($a),'<br>And the Key is at ‘,key($a),'<br>’;

echo ‘Reset ‘,reset($a),'<br>’;

echo ‘The Present Pointer is at : ‘,current($a),'<br>And the Key is at ‘,key($a),'<hr>’;

$a = array(‘Name’=>’Rajesh’,’Age’=>30);

r(Each($a),’Each Method’);         r(Each($a),’Each Method’);

$a = array(‘ram’,’processor’,’computer’);

list($gb,$intel,$dell) = $a;

echo “$gb & $intel together makes $dell faster<br><hr>”;

$str = “write some large text matter.”;

echo $str,'<br><hr>’;

echo ‘<h2>Wordwrap</h2>’; echo wordwrap($str,20,'<br>’,true);   ?>

String builtin function: –


echo ‘<h2>’;

$str = “lamp institute”;

echo “Normal String = “,$str,'<br>’;

echo “Length of String = “,strlen($str),'<br>’;

echo “To Upper Case = “,strtoUpper($str),'<br>’;

echo “To Lower Case = “,strtoLower($str),'<br>’;

echo “Upper case First Word = “,ucfirst($str),'<br>’;

echo “Upper case words = “,ucwords($str),'<br>’;

echo ‘Reverse = ‘,strrev($str),'<br>’;

echo ‘<hr>’;

echo ‘Position of str = ‘,strpos($str,’t’),'<br>’;

echo ‘last Position of str = ‘,strrpos($str,’t’),'<br>’;

echo ‘Postion of str after t again = ‘,strpos($str,’t’,9),'<br>’;

echo ‘Position insensitive = ‘,stripos($str,’lamp’),'<br>’;

echo ‘last position at t insensitive  = ‘,strripos($str,’T’),'<br>’;

echo ‘strstr will extract the entire string : ‘,strstr($str,”In”),'<br>’;

echo ‘strstr will extract the entire string : ‘,stristr($str,”in”),'<br>’;

$name = ‘Rajesh Kumar’;

echo “substr = “,substr($name,0),'<br>’;

echo “substr = “,substr($name,7,4),'<br>’;

echo “substr = “,substr($name,-5,-1),'<br>’;

$url = ‘http://www.google.com?status=active’;

$url .= ‘&’;

echo ‘substr = ‘,substr($url,0,-1),'<br>’;

echo ‘replace = ‘,str_ireplace(‘lamp’,’Apache’,$str),'<br>’;

$a =  ‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789′;

echo str_shuffle($a),'<hr>’;

echo substr(str_shuffle($a),0,12);

echo ‘<hr>’;

$name = “O’henry”;

echo $name,'<br>’;

echo addslashes($name),'<br>’;

echo stripslashes(‘O\’henry’),'<br>’;

echo strip_tags(“<b><i>Hi i am not feeling well</i></b>”);

echo ‘<hr>’;echo ‘<h2>’;

$pwd = ‘computer’;

echo ‘Original Name : ‘,$pwd,'<br>’;

echo ‘<h1 align=”center”>One Way Encrypt</h1>’;

echo ‘Encrypt with MD5 = ‘,md5($pwd),'<br>’;//32 char value

echo ‘Encrypt with MD5 strict = ‘,md5($pwd,true),'<br>’;//16 bit binary format

echo ‘Encrypt with sha1 = ‘,sha1($pwd),'<br>’;//40 char vlaue

echo ‘Encrypt with sha1 strict= ‘,sha1($pwd,true),'<br>’;//20 binary vlaue

echo ‘Crypt = ‘,crypt($pwd),'<br>’;

echo ‘crypt salt = ‘,crypt($pwd,’d4′),'<br>’;

echo ‘<h1 align=”center”>Encrypt & Decrypt Method</h1>’;

echo ‘encrypt = ‘,base64_encode($pwd),'<br>’;

echo ‘decrypt = ‘,base64_decode(‘Y29tcHV0ZXI=’),'<br>’;

echo ‘<h1 align=”center”>Url Encode & Decode</h1>’;

$url = ‘http://www.lamp.com?status=success&id=7&pid=20’;

echo ‘Original url = ‘,$url,'<br>’;

echo ‘encode = ‘,urlencode($url),'<br>’;

echo ‘decode = ‘,urldecode(‘http%3A%2F%2Fwww.lamp.com%3Fstatus%3Dsuccess%26id%3D7%26pid%3D20′),'<br><hr>’;

echo ‘<pre>’;

$name = ”      Rajesh      “;

echo ‘My name is :’,$name,'<br>’;

echo ‘My name is :’,rtrim($name),'<br>’;

echo ‘My name is :’,ltrim($name),'<br>’;

echo ‘My name is :’,trim($name),'<br>’;

echo ‘</pre>’;



FILE:- The full path and filename of the file. If used inside an include, always contains an absolute path with symlinks

LINE:-The current line number of the file.

DIR:-The directory of the file.

Realpath:-Returns absolute pathname

Basename:-Returns filename component of path

Ex: – <?php

echo “File Information : “,__FILE__,'<br>’;

echo “Base Name : “,basename(__FILE__),'<br>’;

echo “Directory Name : “,dirname(__FILE__),'<br>’;

echo “Directory Name : “,__dir__,'<br>’;

echo “real Path : “,realpath(__FILE__),'<br>’;

//echo “real Path : “,realpath(‘../..’),'<br>’;

echo “Line NO : “,__LINE__,'<br>’;

echo ‘<hr>’;

$a = pathinfo(__FILE__);


foreach($a as $k=>$v){

echo $k,’ = ‘,$v,'<br>’;



1) stat(file path) : file function Return an array with file information

2)is_file(file path) : checks wheather the file exist or not & Returns boolean.

3)file_get_contents(file Path) : Returns the file content as a string.

4)file_put_contents(fiel path,data) : writes the content to the file overwriting old content & iffile does not exists, creates a new file & adds the content..This function is introduced in 5th version)

5)file(file path) : Returns the file content as an array with each line in the file at a particular index position.

6)filectime(path) : creates the time of the file.

7)fileatime(file path) : last access time of the path file.

8)filemtime(file path) : last modified time of the file.

9)unlink(file path) : Removes the file from the location.

10)filesize(file path) : Returns the size of the file in bites..

11)filetype(file Path) : Returns the type of the file..(dir or file)

fopen(file path,mode) : Opens the file in the specified mode &returns a file handler for handling the file.

fread(file handler, size) : Reads the file content from the current file handler position upto the specified size.

$fp -> file Pointer ..The internal handler which is used for handling the file.

fgetc(file handler) : Reads a single char in the string.

fgets(file handler) : Reads a single line from the file..

fgetss(file handler) : Reads a single line from the file stripping of html tags in the file…

fwrite(file handler) : This function is used to write the content to the file..

ftell(file handler) : retruns the file handler position in the file

fseek(file handler) : Moves the file handler to the specified position in the file

fclose(file handler) : Closes the File handler connection.

List of Modes :

r           –> Read Mode

r+         –> Read and Write.

w         –> Write Mode

w+       –> Write & Read.

a          –> Append (also writing but without overwriting files)

a+        –> append & read.

x          –> Creates a new file & write..

x+        –> Creat a new file for write and read.


rb,rb+,wb,wb+,ab,ab+,xb,xb+ are the modes to be used for binary files

for above specified action…



$file = ‘a.txt’;

file_put_contents($file,str_repeat(“MOd “,5));


<?php      $file = ‘c.txt’;

$fp = fopen($file,”x”);

fwrite($fp,” Created”);


if(is_file($file)){ echo file_get_contents($file); }



$file = ‘b.txt’;

$fp = fopen($file,”w”);




echo file_get_contents($file);




$file = ‘test.txt’;

$fp = fopen($file,”r”);

echo “Pos : “,ftell($fp),'<br>’;

echo fread($fp,3),'<br>’;

echo “Pos : “,ftell($fp),'<br>’;

echo fgetc($fp),'<br>’;

echo “Pos : “,ftell($fp),'<br>’;

echo fgets($fp),'<br>’;

echo fgets($fp),'<br>’;

echo ‘Pos : ‘,ftell($fp),'<Br>’;

echo fgets($fp),'<br>’;


echo fgetss($fp),'<br>’;





$file = ‘test.txt’;


echo ‘<br>’;

echo “size : “,filesize($file),'<br>’;

echo “Type : “,filetype($file),'<br>’;

echo “Created : “,date(“d-m-y h:i:s”,filectime($file)),'<br>’;

echo “Accessed : “,date(“d-m-y h:i:s”,fileatime($file)),'<br>’;

echo “Modified : “,date(“d-m-y h:i:s”,filemtime($file)),'<br>’;

echo file_get_contents($file),'<br>’;

echo “<pre>”;


echo ‘<br>’;




$file = ‘b.txt’;

$fp = fopen($file,”a”);




echo file_get_contents($file);






$file = ‘a.txt’;


Directory files: –

getcwd() : current working directory,

chdir(path) : change current working dir to argumented path.

is_dir(path) : checks wheather the argumented dir exist or not and return boolean.

mkdir(dirname) : makes a directory on the current working location.

rename(old name,new name): changes the name of the directory.

rmdir(dir name) : removes the directory.

scandir(path) : scan the dir & return the directory content as an array .. Returns an array with path related information.



echo ‘Cwd : ‘,getcwd(),'<br>’;

$a = scandir(‘.’,0);

foreach($a as $k=>$v){

echo “$k == $v<br>”;


chdir(‘..’);echo ‘<hr>’;

echo ‘Cwd : ‘,getcwd(),'<br><hr>’;

$a = scandir(‘.’,0);

foreach($a as $k=>$v){

echo “$k == $v<br>”;





$dir = ‘test’;



echo “Directory is created”;


else {

echo “Directory already exists”;




$dir = ‘test’;

$new = “modified”;



echo “Directory name is $new”;


else {

echo “Directory does not exists”;









$new = “modified”;



echo “Directory is removed”;


else {

echo “Directory does not exists”;




echo ‘<pre>’;


Super globals: –

Difference between GET and POST:-

GET                                                                                                   POST

1.GET data  transfers through URL.                          POST data is send through request headers

2.GET is insecure                                                        POST is secure

3.File cannot be transfered using GET                                   Files can be transfered

4.Limited data can be send based on length              We can send huge data(8MB) which can be scaled

of URL supported by browser(2KB).                                    up by using POST_MAX_SIZE

5.It is fast                                                                    It is not as fast as GET.

6.$_GET is used for accessing the GET parameters   $_POST is used for accessing the POST



Get ex: -get.php



echo ‘Name : ‘,$_GET[‘fname’],'<br>’;

echo ‘Email Address : ‘,$_GET[’email’],'<br>’;

$gend = ($_GET[‘gender’] == ‘m’)?’Male’:’Female’;

echo ‘Gender : ‘,$gend,'<br>’;   }

echo ‘<hr>’;

echo urldecode($_SERVER[‘QUERY_STRING’]);echo ‘<hr><br>’;


<form method=’GET’ action=’get.php’>

Name : <input type=’text’ name=’fname’ value=”><br>

E-Mail : <input type=’text’ name=’email’ value=”><br>

Gender : <input type=’radio’ name=’gender’ value=’m’> Male <input type=’radio’ name=’gender’ value=’f’> Female<br>

<input type=’submit’ name=’submit’ value=’Register !’>  </form>

Post ex: -post.php



echo ‘Name : ‘,$_POST[‘fname’],'<br>’;

echo ‘Email Address : ‘,$_POST[’email’],'<br>’;

$gend = ($_POST[‘gender’]==’m’)?’Male’:’Female’;

echo ‘Gender : ‘,$gend,'<br>’;

$a = $_POST[‘course’];

echo $a,'<br><hr>’;     print_r($a);      }

echo ‘<hr>’;

echo ‘The query string : ‘,$_SERVER[‘QUERY_STRING’],'<br>’;


<form method=’POST’ action=’post.php’/>

Name : <input type=’text’ name=’fname’ value=”/><br>

E-Mail : <input type=’text’ name=’email’ value=”/><br>

Gender : <input type=’radio’ name=’gender’ value=’m’/> Male <input type=’radio’ name=’gender’ value=’f’/> Female <br>

Hobbies : <br>

<input type=’checkbox’ name=’course[]’ value=’c’/> C-Language <br>

<input type=’checkbox’ name=’course[]’ value=’p’/> PHP <br>

<input type=’checkbox’ name=’course[]’ value=’j’/> Java <br>

<input type=’submit’ name=’submit’ value=’Register’/>



servervariables.php:-  <?php

echo ‘Get Environment : ‘,getenv(‘os’),'<br>’;

echo ‘Environment Path : ‘,getenv(‘path’),'<br>’;               echo ‘<hr>’;

echo ‘Document Root : ‘,$_SERVER[‘DOCUMENT_ROOT’],'<br>’;

echo ‘Http Host : ‘,$_SERVER[‘HTTP_HOST’],'<br>’;

echo ‘Referer : ‘,$_SERVER[‘HTTP_REFERER’],'<br>’;

echo ‘Method : ‘,$_SERVER[‘REQUEST_METHOD’],'<br>’;

echo ‘User Agent : ‘,($_SERVER[‘HTTP_USER_AGENT’]),'<br>’;

echo ‘Name of Script : ‘,$_SERVER[‘SCRIPT_NAME’],'<br>’;

echo ‘Query String : ‘,$_SERVER[‘QUERY_STRING’],'<br>’;

echo ‘Remote Ip Address : ‘,$_SERVER[‘REMOTE_ADDR’],'<br>’;

echo ‘PHP Self : ‘,$_SERVER[‘PHP_SELF’],'<br>’;

echo ‘Request URL : ‘,$_SERVER[‘REQUEST_URI’],'<br>’;

echo ‘Script File Name : ‘,$_SERVER[‘SCRIPT_FILENAME’],'<br>’;



echo phpinfo();

Include_once and required _once: –these both will include file very first time and if already file has been included this will not include for the second time.

Defference between include_once & include: – include and include _once will include the files. But if the path of the file is wrong include and include_once will generate the wrong message and rest of the code will be excuted

Required and required_once: – if location of the path is given wrong this will through a wrong as well as path error and code gets alted for the execution will be stop

Note: –include and require if you are calling a file you have to be predation whether the file having are’t if function exist if you have to make function as it using function exist as a method

Ex: – a.php



</style> <b>I am included</b><br><hr>

<?php   $a = 10;


function r(){    echo ‘I am in a.php and working fine<br>’;    }   } ?>






$b = 20;

echo ‘The Value of $a = ‘,$a,'<br>’;

echo ‘The Value of $b = ‘,$b,'<br>’;

r();     ?>

0 Responses on Functions in PHP"

Leave a Message

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

Copy Rights Reserved © Mindmajix.com All rights reserved. Disclaimer.