SlideShare a Scribd company logo
Php MySql part -3
    Subhasis Nayak

   CMC
Contents
    Using functions
    Defining functions
    Arguments & parameters
    Default argument values
    Variable scope
    Using library files
    Including library files
Using functions
 Functions are used to do certain actions. It consists block of code.
    When we call a function it runs the code and give a result,
   It may takes outside values.
   It may return values to outside.
   When we call a function it jumps to the definition of that function
    and start processing codes which are inside of the ―{}‖ and once
    completes it jumps back to the next line from where it was called.
   PHP contains many wide range built in functions which can be
    used to do solve many tasks.
User defined function
   We will put some reusable code into function and use it again
    and again. Here we can change the function if we want to
    change how does it work or processing the block of code.
   We can maintain our code easily and quickly.
   Reduce the duplication of code.
   Reduce the effort and time.
   Changing the function definition effect all over where it is
    called.
Defining function
 In php to define function we need the key word ―function‖
  and then name of the function.
 Here we do not need any return type. What ever we
  returned by default it will get it’s data type.
 But when we want to return from the function we have to
  use keyword ‖return‖.

               function add(int x, int y){
               return (x+y);
               }
An example.
Arguments & parameters
   When we define the function we used variables with in the
    first bracket.
   On that time those variables are known as parameter lists.
   When we call function using variables those are called
    arguments.
   Well, arguments are used to pass the outside variables as local
    variables of local variables of function.
   If we want to use GLOBAL variable use GLOBAL keyword
    before it.
An example
Default arguments
 Let’s we use 2 – parameters. If we do not pass two arguments
  we will get an error.
 In complex logic sometimes we do not need all the
  arguments. On this case what will we do.
 Thanks to PHP it provides us a feature through which we can
  make our arguments default.
 To write a default argument, we have to initialize the
  parameters when we use them on first bracket. Let’s see.
Cont’d …..
function myFunc($a=0){
                         As I am not passing
Return a;                any argument it will
}                          take default one.
echo myFunc();

function myFunc($a){
                          As I am not passing
Return a;                 any argument it will
}                            give an error.
echo myFunc();
Variable scope
 The reason values have to be passed in to functions as
  arguments has to do with variable scope—the rules that
  determine what sections of script are able to access which
  variables.
 The basic rule is that any variables are:
     Variable defined in the main body of the script cannot be used
      inside a function.
     any variables used inside a function cannot be seen by the main
      script.
Cont’d ……
 Local – variables within a function are said to be local
  variables or that their scope is local to that function.
 Global - Variables that are not local are called global
  variables.
 Local and global variables can have the same name and
  contain different values.
 To access global variable inside the function use keyword
  ‖global‖ as prefix of the variable
An example

             Give output 250




              Give an error
Using library files
 If we want to use it again in other scripts. Rather than copy
  the function definition into each script that needs to use it,
  you can use a library file so that your function needs to be
  stored and maintained in only one place.
 A library file needs to enclose its PHP code inside <?php tags
  just like a regular script; otherwise, the contents will be
  displayed as HTML when they are included in a script.
 To do so create a ―.php‖ file put your all functions.
Including library files
 To incorporate an external library file into another script,
  you use the include keyword.
 The include path Setting By default, include searches only the
  current directory and a few system locations for files to be
  included.
 If you want to include files from another location, you can
  use a path to the file.
 You can use the include_once keyword if you want to
  make sure that a library file is loaded only once.
Cont’d …..
 If a script attempts to define the same function a second
  time, an error will result.
 Using include_once helps to avoid this, particularly when
  files are being included from other library files.let’ds do it
  practically.
An example
   I write a function ―add_tax‖ in ―addTax.php‖
Next write a file “useTax.php”
   Use include_once/include to add like below:
     include_once "addTax.php";
   Then call the function “add_tax()” any where in
    your block. I used in this way.

More Related Content

PDF
Function arguments In Python
Amit Upadhyay
 
PPTX
Python Functions
Mohammed Sikander
 
PPTX
Functions in python slide share
Devashish Kumar
 
PDF
Function in Python
Yashdev Hada
 
PPT
Python Built-in Functions and Use cases
Srajan Mor
 
PPTX
Functions in Python
Shakti Singh Rathore
 
PPTX
Function Parameters
primeteacher32
 
Function arguments In Python
Amit Upadhyay
 
Python Functions
Mohammed Sikander
 
Functions in python slide share
Devashish Kumar
 
Function in Python
Yashdev Hada
 
Python Built-in Functions and Use cases
Srajan Mor
 
Functions in Python
Shakti Singh Rathore
 
Function Parameters
primeteacher32
 

What's hot (20)

PPTX
Java script function
suresh raj sharma
 
PPTX
Functions in python
colorsof
 
PPS
Introduction to php 5
pctechnology
 
PDF
Chapter 11 Function
Deepak Singh
 
PPTX
Functions
Septi Ratnasari
 
PPTX
FUNCTION CPU
Krushal Kakadia
 
PPTX
Python and You Series
Karthik Prakash
 
PPTX
C++ Functions
Jari Abbas
 
PDF
Handout # 4 functions + scopes
NUST Stuff
 
PDF
Python Function and Looping
Novita Sari
 
PDF
Functional JavaScript Fundamentals
Srdjan Strbanovic
 
PPT
Command line arguments.21
myrajendra
 
PPT
Advanced Javascript
relay12
 
PDF
Functions in php
AbdulAzizSapra
 
PPTX
Function Parameters
primeteacher32
 
PDF
Write codeforhumans
Narendran R
 
DOC
Java Script Language Tutorial
vikram singh
 
PPTX
Inline function
Tech_MX
 
PPT
Basic information of function in cpu
Dhaval Jalalpara
 
Java script function
suresh raj sharma
 
Functions in python
colorsof
 
Introduction to php 5
pctechnology
 
Chapter 11 Function
Deepak Singh
 
Functions
Septi Ratnasari
 
FUNCTION CPU
Krushal Kakadia
 
Python and You Series
Karthik Prakash
 
C++ Functions
Jari Abbas
 
Handout # 4 functions + scopes
NUST Stuff
 
Python Function and Looping
Novita Sari
 
Functional JavaScript Fundamentals
Srdjan Strbanovic
 
Command line arguments.21
myrajendra
 
Advanced Javascript
relay12
 
Functions in php
AbdulAzizSapra
 
Function Parameters
primeteacher32
 
Write codeforhumans
Narendran R
 
Java Script Language Tutorial
vikram singh
 
Inline function
Tech_MX
 
Basic information of function in cpu
Dhaval Jalalpara
 
Ad

Similar to Php, mysq lpart3 (20)

PPT
PHP - Introduction to PHP Functions
Vibrant Technologies & Computers
 
PPT
PHP-03-Functions.ppt
Jamers2
 
PPT
PHP-03-Functions.ppt
ShishirKantSingh1
 
PPT
Understanding PHP Functions: A Comprehensive Guide to Creating
jinijames109
 
PPTX
Arrays &amp; functions in php
Ashish Chamoli
 
PPT
PHP Fuctions.ppt,IT CONTAINS PHP INCLUDE FUNCTION
ashokkumar910878
 
PPTX
Functions in PHP.pptx
Japneet9
 
PDF
Php Tutorials for Beginners
Vineet Kumar Saini
 
PDF
php AND MYSQL _ppt.pdf
SVN Polytechnic Kalan Sultanpur UP
 
PDF
PHP Unit 3 functions_in_php_2
Kumar
 
PPTX
UNIT- 2 Functions__________________.pptx
harleensingh985
 
PPTX
PHPneweeeeeeeeeeeeeeeeeeeeeeeeeeeeee.pptx
kamalsmail1
 
PPTX
function in php like control loop and its uses
vishal choudhary
 
PDF
Wt unit 4 server side technology-2
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
PPTX
Web Application Development using PHP Chapter 3
Mohd Harris Ahmad Jaal
 
PPTX
function in php using like three type of function
vishal choudhary
 
PPT
Class 3 - PHP Functions
Ahmed Swilam
 
PDF
4.2 PHP Function
Jalpesh Vasa
 
PPTX
Introduction in php part 2
Bozhidar Boshnakov
 
PPTX
PHP FUNCTIONS AND ARRAY.pptx
ShaliniPrabakaran
 
PHP - Introduction to PHP Functions
Vibrant Technologies & Computers
 
PHP-03-Functions.ppt
Jamers2
 
PHP-03-Functions.ppt
ShishirKantSingh1
 
Understanding PHP Functions: A Comprehensive Guide to Creating
jinijames109
 
Arrays &amp; functions in php
Ashish Chamoli
 
PHP Fuctions.ppt,IT CONTAINS PHP INCLUDE FUNCTION
ashokkumar910878
 
Functions in PHP.pptx
Japneet9
 
Php Tutorials for Beginners
Vineet Kumar Saini
 
php AND MYSQL _ppt.pdf
SVN Polytechnic Kalan Sultanpur UP
 
PHP Unit 3 functions_in_php_2
Kumar
 
UNIT- 2 Functions__________________.pptx
harleensingh985
 
PHPneweeeeeeeeeeeeeeeeeeeeeeeeeeeeee.pptx
kamalsmail1
 
function in php like control loop and its uses
vishal choudhary
 
Wt unit 4 server side technology-2
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
Web Application Development using PHP Chapter 3
Mohd Harris Ahmad Jaal
 
function in php using like three type of function
vishal choudhary
 
Class 3 - PHP Functions
Ahmed Swilam
 
4.2 PHP Function
Jalpesh Vasa
 
Introduction in php part 2
Bozhidar Boshnakov
 
PHP FUNCTIONS AND ARRAY.pptx
ShaliniPrabakaran
 
Ad

More from Subhasis Nayak (20)

PDF
Php, mysq lpart5(mysql)
Subhasis Nayak
 
PDF
working with database using mysql
Subhasis Nayak
 
PDF
Php, mysq lpart4(processing html form)
Subhasis Nayak
 
PPT
Jsp 01
Subhasis Nayak
 
PPT
Jsp 02(jsp directives)2003
Subhasis Nayak
 
PPT
Php, mysq lpart1
Subhasis Nayak
 
PPT
Php, mysqlpart2
Subhasis Nayak
 
PPTX
C:\fakepath\jsp01
Subhasis Nayak
 
PPTX
Servlet & jsp
Subhasis Nayak
 
PPT
J2ee connector architecture
Subhasis Nayak
 
PPT
how to create object
Subhasis Nayak
 
PDF
Pointer in c++ part3
Subhasis Nayak
 
PDF
Pointer in c++ part2
Subhasis Nayak
 
PDF
Pointer in c++ part1
Subhasis Nayak
 
PDF
C++ arrays part2
Subhasis Nayak
 
ODP
C++ arrays part1
Subhasis Nayak
 
PDF
Introduction to network
Subhasis Nayak
 
PDF
Flow control in c++
Subhasis Nayak
 
PPT
Oops And C++ Fundamentals
Subhasis Nayak
 
PPT
Text mode Linux Installation Part 01
Subhasis Nayak
 
Php, mysq lpart5(mysql)
Subhasis Nayak
 
working with database using mysql
Subhasis Nayak
 
Php, mysq lpart4(processing html form)
Subhasis Nayak
 
Jsp 02(jsp directives)2003
Subhasis Nayak
 
Php, mysq lpart1
Subhasis Nayak
 
Php, mysqlpart2
Subhasis Nayak
 
C:\fakepath\jsp01
Subhasis Nayak
 
Servlet & jsp
Subhasis Nayak
 
J2ee connector architecture
Subhasis Nayak
 
how to create object
Subhasis Nayak
 
Pointer in c++ part3
Subhasis Nayak
 
Pointer in c++ part2
Subhasis Nayak
 
Pointer in c++ part1
Subhasis Nayak
 
C++ arrays part2
Subhasis Nayak
 
C++ arrays part1
Subhasis Nayak
 
Introduction to network
Subhasis Nayak
 
Flow control in c++
Subhasis Nayak
 
Oops And C++ Fundamentals
Subhasis Nayak
 
Text mode Linux Installation Part 01
Subhasis Nayak
 

Recently uploaded (20)

PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
DOCX
Top AI API Alternatives to OpenAI: A Side-by-Side Breakdown
vilush
 
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
AVTRON Technologies LLC
 
PDF
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
 
PDF
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
PDF
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PPTX
C Programming Basics concept krnppt.pptx
Karan Prajapat
 
PDF
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
PDF
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
PDF
DevOps & Developer Experience Summer BBQ
AUGNYC
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
Top AI API Alternatives to OpenAI: A Side-by-Side Breakdown
vilush
 
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
AVTRON Technologies LLC
 
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
 
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
C Programming Basics concept krnppt.pptx
Karan Prajapat
 
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
DevOps & Developer Experience Summer BBQ
AUGNYC
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 

Php, mysq lpart3

  • 1. Php MySql part -3 Subhasis Nayak CMC
  • 2. Contents Using functions Defining functions Arguments & parameters Default argument values Variable scope Using library files Including library files
  • 3. Using functions  Functions are used to do certain actions. It consists block of code. When we call a function it runs the code and give a result,  It may takes outside values.  It may return values to outside.  When we call a function it jumps to the definition of that function and start processing codes which are inside of the ―{}‖ and once completes it jumps back to the next line from where it was called.  PHP contains many wide range built in functions which can be used to do solve many tasks.
  • 4. User defined function  We will put some reusable code into function and use it again and again. Here we can change the function if we want to change how does it work or processing the block of code.  We can maintain our code easily and quickly.  Reduce the duplication of code.  Reduce the effort and time.  Changing the function definition effect all over where it is called.
  • 5. Defining function  In php to define function we need the key word ―function‖ and then name of the function.  Here we do not need any return type. What ever we returned by default it will get it’s data type.  But when we want to return from the function we have to use keyword ‖return‖. function add(int x, int y){ return (x+y); }
  • 7. Arguments & parameters  When we define the function we used variables with in the first bracket.  On that time those variables are known as parameter lists.  When we call function using variables those are called arguments.  Well, arguments are used to pass the outside variables as local variables of local variables of function.  If we want to use GLOBAL variable use GLOBAL keyword before it.
  • 9. Default arguments  Let’s we use 2 – parameters. If we do not pass two arguments we will get an error.  In complex logic sometimes we do not need all the arguments. On this case what will we do.  Thanks to PHP it provides us a feature through which we can make our arguments default.  To write a default argument, we have to initialize the parameters when we use them on first bracket. Let’s see.
  • 10. Cont’d ….. function myFunc($a=0){ As I am not passing Return a; any argument it will } take default one. echo myFunc(); function myFunc($a){ As I am not passing Return a; any argument it will } give an error. echo myFunc();
  • 11. Variable scope  The reason values have to be passed in to functions as arguments has to do with variable scope—the rules that determine what sections of script are able to access which variables.  The basic rule is that any variables are:  Variable defined in the main body of the script cannot be used inside a function.  any variables used inside a function cannot be seen by the main script.
  • 12. Cont’d ……  Local – variables within a function are said to be local variables or that their scope is local to that function.  Global - Variables that are not local are called global variables.  Local and global variables can have the same name and contain different values.  To access global variable inside the function use keyword ‖global‖ as prefix of the variable
  • 13. An example Give output 250 Give an error
  • 14. Using library files  If we want to use it again in other scripts. Rather than copy the function definition into each script that needs to use it, you can use a library file so that your function needs to be stored and maintained in only one place.  A library file needs to enclose its PHP code inside <?php tags just like a regular script; otherwise, the contents will be displayed as HTML when they are included in a script.  To do so create a ―.php‖ file put your all functions.
  • 15. Including library files  To incorporate an external library file into another script, you use the include keyword.  The include path Setting By default, include searches only the current directory and a few system locations for files to be included.  If you want to include files from another location, you can use a path to the file.  You can use the include_once keyword if you want to make sure that a library file is loaded only once.
  • 16. Cont’d …..  If a script attempts to define the same function a second time, an error will result.  Using include_once helps to avoid this, particularly when files are being included from other library files.let’ds do it practically.
  • 17. An example  I write a function ―add_tax‖ in ―addTax.php‖
  • 18. Next write a file “useTax.php”  Use include_once/include to add like below:  include_once "addTax.php";  Then call the function “add_tax()” any where in your block. I used in this way.