SlideShare a Scribd company logo
2
Most read
4
Most read
15
Most read
PHP Function
By:- Jalpesh Vasa
PHP Functions
• Heart of well-organized script
• Block of code that is not immediately
executed, but can be called by your script
when needed.
• Basically 2 types:
 Built-in
 User-defined
PHP Functions(Built in)
• PHP Array Function
• PHP Calendar Function
• PHP class/object Function
• PHP Date/Time Function
• PHP Directory Function
• PHP Error Handling Function
• PHP File System Function
• PHP MySQL Function
• PHP Network Function
• PHP String Function
• PHP ODBC Function
• PHP XML Parsing Function
PHP Functions (Built-in)
• include() – include content of one file to php
file.
 gives warning if file not found and
continuing executing script
• require() - compulsory include the specified
file.
 gives fatal error and stops executing script
furhter .
PHP Functions (Built-in)
• Eg. <html><body><h1>hello</h1><p> ok</p>
<?php include(‘a1.php’);?>
<?php include ‘a1.txt’; ?>
</body></html>
• Eg. <body>
<h1>Welcome to my home page!</h1>
<?php include 'vars.php';
echo "I have a $color $car.";
?>
</body>
<?php
$color='red';
$car='BMW';
?>
vars.php
PHP Functions (Built-in)
• Eg. <html><body><h1>hello</h1><p> ok</p>
<?php include ‘vars1.php’;
echo “you have $color $car”;
?>
</body></html>
• Eg. <body>
<h1>Welcome to my home page!</h1>
<?php require 'vars1.php';
echo "I have a $color $car.";
?>
</body>
<?php
$color='red';
$car='BMW';
?>
vars.php
PHP Functions(User defined)
• Information to be passed to them & usually
return value.
• Function name are case-insensitive
• All function require parenthesis
• Defining a user-defined function:
function fun_name(arg1,arg2)
{
----
----
}
PHP Functions
<?php
function bigh()
{
echo “hello”;
}
bigh();
Bigh();
?>
PHP Functions
<?php
function printB($txt)
{
echo “$txt<br>”;
}
printB(“This is line”);
printB(“hello”);
printB(“hi”);
?>
PHP Functions
<?php
function addnum($n1, $n2)
{
$result = $n1+$n2;
return $result;
}
echo addnum(3,4);
?>
PHP Functions
• Dynamic function call
It is possible to assign function name as strings to
variables & then treat variables exactly function name
itself.
<?php
function say()
{
echo “hello<br>”;
}
$fun_name = “say”;
$fun_name();
?>
PHP Functions
• Variable declared within a function remains
local to that function
 not available outside function or within other
function
function hello()
{ $var1 = “hi”;
echo “variable is $var1”;
}
PHP Functions
$var2 = “hello”;
function f1()
{
echo “variable is $var2”; //inaccessible
}
f1();
PHP Functions
$var2 = 42;
function f1()
{ global $var2;
echo “variable is $var2”; //accessible
}
f1();
PHP Functions
function foo()
{
function bar()
{
echo “hi”; // doesn’t exist until foo is called.
}
}
PHP Functions
function be($h=30)
{
echo $h;
}
Be(450);
be();
be(21);

More Related Content

PPTX
PHP FUNCTIONS
PPT
PHP variables
PDF
Bootstrap
PDF
Php array
PDF
Php tutorial(w3schools)
PPTX
Critical Path Ppt
PPTX
Univariate Analysis
PPTX
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
PHP FUNCTIONS
PHP variables
Bootstrap
Php array
Php tutorial(w3schools)
Critical Path Ppt
Univariate Analysis
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT

What's hot (20)

PPT
Class 5 - PHP Strings
PDF
JavaScript - Chapter 12 - Document Object Model
PPTX
Lesson 2 php data types
PPSX
Php and MySQL
PPTX
Event In JavaScript
PDF
Java I/o streams
PPTX
Php basics
PPT
PHP - Introduction to PHP Forms
PDF
Php introduction
PPT
PHP - Introduction to Object Oriented Programming with PHP
PDF
jQuery for beginners
PPT
Introduction to JavaScript
PPTX
Php cookies
PPTX
Lab #2: Introduction to Javascript
PPTX
Statements and Conditions in PHP
PPT
Oops concepts in php
PPTX
Php.ppt
PPT
MYSQL - PHP Database Connectivity
PPT
Php forms
Class 5 - PHP Strings
JavaScript - Chapter 12 - Document Object Model
Lesson 2 php data types
Php and MySQL
Event In JavaScript
Java I/o streams
Php basics
PHP - Introduction to PHP Forms
Php introduction
PHP - Introduction to Object Oriented Programming with PHP
jQuery for beginners
Introduction to JavaScript
Php cookies
Lab #2: Introduction to Javascript
Statements and Conditions in PHP
Oops concepts in php
Php.ppt
MYSQL - PHP Database Connectivity
Php forms
Ad

Similar to 4.2 PHP Function (20)

PDF
Wt unit 4 server side technology-2
PPTX
function in php using like three type of function
PPTX
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
PPT
PHP-03-Functions.ppt
PPT
PHP-03-Functions.ppt
PPTX
function in php like control loop and its uses
PPT
Php Tutorial
PDF
Module-3 15CS71-WTA-Serverside Development with PHP
PPTX
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
PPTX
php basics
PPT
Hacking with hhvm
PPT
php 1
PPT
PHP - Introduction to PHP Fundamentals
KEY
GettingStartedWithPHP
PPT
PHP - Introduction to PHP Functions
PPT
PHP Fuctions.ppt,IT CONTAINS PHP INCLUDE FUNCTION
PPT
Prersentation
PDF
Phpbasics
PPTX
PHP from soup to nuts Course Deck
Wt unit 4 server side technology-2
function in php using like three type of function
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
PHP-03-Functions.ppt
PHP-03-Functions.ppt
function in php like control loop and its uses
Php Tutorial
Module-3 15CS71-WTA-Serverside Development with PHP
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
php basics
Hacking with hhvm
php 1
PHP - Introduction to PHP Fundamentals
GettingStartedWithPHP
PHP - Introduction to PHP Functions
PHP Fuctions.ppt,IT CONTAINS PHP INCLUDE FUNCTION
Prersentation
Phpbasics
PHP from soup to nuts Course Deck
Ad

More from Jalpesh Vasa (16)

PDF
Object Oriented PHP - PART-1
PDF
Object Oriented PHP - PART-2
PDF
5. HTML5
PDF
4.4 PHP Session
PDF
4.3 MySQL + PHP
PDF
4.1 PHP Arrays
PDF
4 Basic PHP
PDF
3.2.1 javascript regex example
PDF
3.2 javascript regex
PDF
3. Java Script
PDF
3.1 javascript objects_DOM
PDF
2 introduction css
PDF
1 web technologies
PDF
Remote Method Invocation in JAVA
PDF
Kotlin for android development
PDF
Security in php
Object Oriented PHP - PART-1
Object Oriented PHP - PART-2
5. HTML5
4.4 PHP Session
4.3 MySQL + PHP
4.1 PHP Arrays
4 Basic PHP
3.2.1 javascript regex example
3.2 javascript regex
3. Java Script
3.1 javascript objects_DOM
2 introduction css
1 web technologies
Remote Method Invocation in JAVA
Kotlin for android development
Security in php

Recently uploaded (20)

PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
Complications of Minimal Access Surgery at WLH
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
RMMM.pdf make it easy to upload and study
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Basic Mud Logging Guide for educational purpose
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Pre independence Education in Inndia.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Final Presentation General Medicine 03-08-2024.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Cell Types and Its function , kingdom of life
Complications of Minimal Access Surgery at WLH
PPH.pptx obstetrics and gynecology in nursing
RMMM.pdf make it easy to upload and study
Microbial diseases, their pathogenesis and prophylaxis
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Basic Mud Logging Guide for educational purpose
01-Introduction-to-Information-Management.pdf
Cell Structure & Organelles in detailed.
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Anesthesia in Laparoscopic Surgery in India
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Pre independence Education in Inndia.pdf
VCE English Exam - Section C Student Revision Booklet
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf

4.2 PHP Function

  • 2. PHP Functions • Heart of well-organized script • Block of code that is not immediately executed, but can be called by your script when needed. • Basically 2 types:  Built-in  User-defined
  • 3. PHP Functions(Built in) • PHP Array Function • PHP Calendar Function • PHP class/object Function • PHP Date/Time Function • PHP Directory Function • PHP Error Handling Function • PHP File System Function • PHP MySQL Function • PHP Network Function • PHP String Function • PHP ODBC Function • PHP XML Parsing Function
  • 4. PHP Functions (Built-in) • include() – include content of one file to php file.  gives warning if file not found and continuing executing script • require() - compulsory include the specified file.  gives fatal error and stops executing script furhter .
  • 5. PHP Functions (Built-in) • Eg. <html><body><h1>hello</h1><p> ok</p> <?php include(‘a1.php’);?> <?php include ‘a1.txt’; ?> </body></html> • Eg. <body> <h1>Welcome to my home page!</h1> <?php include 'vars.php'; echo "I have a $color $car."; ?> </body> <?php $color='red'; $car='BMW'; ?> vars.php
  • 6. PHP Functions (Built-in) • Eg. <html><body><h1>hello</h1><p> ok</p> <?php include ‘vars1.php’; echo “you have $color $car”; ?> </body></html> • Eg. <body> <h1>Welcome to my home page!</h1> <?php require 'vars1.php'; echo "I have a $color $car."; ?> </body> <?php $color='red'; $car='BMW'; ?> vars.php
  • 7. PHP Functions(User defined) • Information to be passed to them & usually return value. • Function name are case-insensitive • All function require parenthesis • Defining a user-defined function: function fun_name(arg1,arg2) { ---- ---- }
  • 8. PHP Functions <?php function bigh() { echo “hello”; } bigh(); Bigh(); ?>
  • 9. PHP Functions <?php function printB($txt) { echo “$txt<br>”; } printB(“This is line”); printB(“hello”); printB(“hi”); ?>
  • 10. PHP Functions <?php function addnum($n1, $n2) { $result = $n1+$n2; return $result; } echo addnum(3,4); ?>
  • 11. PHP Functions • Dynamic function call It is possible to assign function name as strings to variables & then treat variables exactly function name itself. <?php function say() { echo “hello<br>”; } $fun_name = “say”; $fun_name(); ?>
  • 12. PHP Functions • Variable declared within a function remains local to that function  not available outside function or within other function function hello() { $var1 = “hi”; echo “variable is $var1”; }
  • 13. PHP Functions $var2 = “hello”; function f1() { echo “variable is $var2”; //inaccessible } f1();
  • 14. PHP Functions $var2 = 42; function f1() { global $var2; echo “variable is $var2”; //accessible } f1();
  • 15. PHP Functions function foo() { function bar() { echo “hi”; // doesn’t exist until foo is called. } }
  • 16. PHP Functions function be($h=30) { echo $h; } Be(450); be(); be(21);