ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing

ExpertRating Home
ExpertRating Benefits
Recommend ExpertRating
Suggest More Tests
Privacy Policy
FAQ
Login
 
PHP Tutorial - Index
PHP Tutorial - Introduction to PHP
PHP Tutorial - Your First PHP Script
PHP Tutorial - Operators
PHP Tutorial - Conditional and Looping
PHP Tutorial - Functions
PHP Tutorial - Classes and Objects
PHP Tutorial - Working with Forms
PHP Tutorial - Advanced PHP Topics
PHP Tutorial - Advanced Class Concepts
     

 
Online Personal Trainer Certification
Personal Trainer Certification (Spanish)
Six Sigma Certification
Find a Personal Trainer
Project Management Certification
Six Sigma Certification
Six Sigma Black Belt Certification
Master Black Belt Certification
Six Sigma Green Belt Certification
Life Coach Certification
Lean Management Certification
Lean Six Sigma Certification
First Aid Certification
CPR Certification
Yoga Certification
Aerobics Certification
Pilates Certification
Business Analyst Certification
SEO Certification
Online Business Writing Course & Certification
Makeup Artist Certification
Baby Sitting Course & Certification
Time Management Certification
Health Club Management Certification
Medical Coding Certification
Medical Billing Certification
Business Analysis Course
Master Trainer Certification
Total Quality Management Certification
Kaizen Certification
Creative Writing Certification
Event Management Certification
Test Search by Job Title
Administrative Assistant Certification
Virtual Assistant Certification
  All Online Courses
   

   
   
   
   
   
   

   
  Home > Courses, Tutorials & eBooks > PHP Tutorial > Functions
 

PHP Tutorial - Functions

 
Page 2 of 3
 

Functions within Functions

In PHP a function can be embedded within a function. If a function is embedded within a function, then in order to call that function we have to first call the parent function. If we directly try to call the embedded function it will give an error.

In the following example the function func1 is called first and then the function func2 is called. If the function func2 is called without calling the function func1 then it will give an error.

 

Example:

<html>

<body>

 

<?php

function func1()

{

function func2()

{

echo "Welcome to expertrating.com! <br/><br/>";

echo "func2() is called after calling func1().\n";

}

}

 

//func1 will be called first.

 

func1();

 

//func2 will be called after calling func1.

 

func2();

?>

 

</body>

</html>

Output

 

Returning Values

In PHP the values are returned from a function by using the “return” statement. With the use of return any type can be returned including string, lists and objects. The return statement ends the execution of the function and passes back the control to the line from which it was called.

In the following example we will see the use of return statement. In this example a function is written which checks for the smaller value. It returns a “yes” if the first value is smaller than the second one and a “no” if its not.

 

Example:

<html>

<body>

 

<?php

function lessthan($a, $b)

{

if($a < $b)

{

return "Yes";

}

else

{

return "No";

}

}

 $xyz = lessthan(26,22);

echo "Is 26 less than 22?----$xyz";

?>

 

</body>

</html>

Output

 

     
 

 

 
     
Home  |  About Us  |  Privacy Policy  |  Site Map  |  FAQs  |  Contact Us
 
© ExpertRating 2015. All Rights Reserved.