Looking for a Tutor Near You?

Post Learning Requirement »
x

Choose Country Code

x

Direction

x

Ask a Question

x

x
x
x
Hire a Tutor

Introduction To PHP

Loading...

Published in: PHP And MySQL
1,498 Views

PHP stands for Hypertext Preprocessor. These notes give a slight introduction to PHP.

Neelam S / Ghaziabad

1 year of teaching experience

Qualification: B.Tech

Teaches: Basic Computer, MS Office, School Level Computer, Computer Science, IT & Computer Subjects, Chemistry, Mathematics, Social Studies, CSS Training, HTML Training, PHP And MySQL

Contact this Tutor
  1. CLASS 5 PHP Functions: A function is a self-contained block of code that performs a specific task. A function will not execute immediately when a page loads. A function will be executed by a call to the function. Creating PHP Function: Function declaration starts with the word "function" Syntax: function functionName() code to be executed; NOTE: A function name can start with a letter or underscore (not a number) Function name are not case-sensitive. For example: < '?php /* Defining a PHP Function */ function firstfun() echo "You are really a nice person, Have a nice time! " • Calling a PHP Function firstfun();
  2. PHP Function with Parameters: Inside a function, parameters work like variables. For example: < '?php function addFunction($num1, $num2) $sum = $numl + $num2; echo "Sum of the two numbers is : $sum"; addFunction(10, 20); Passing Arguments by Reference: This means that a reference to the variable is manipulated by the function rather than a copy of the variable's value. Any changes made to an argument in these cases will change the value of the original variable. We can pass an argument by reference by adding an ampersand to the variable name in either the function call or the function definition. For example: < ?php function addFive(&$num) $num += 5; function addSix(&$num)
  3. $num += 6; $orignum = 10; addFive( $orignum ); echo "Original Value is $orignum"; addSix( $orignum ); echo "Original Value is $orignum"; PHP Function Returning Value: A function can return a value using the return statement in conjunction with a value or object. return stops the execution of the function and sends the value back to the calling code. For example: < '?php function addFunction($num1, $num2) $sum = $numl + $num2; return $sum; $return_value = addFunction(10, 20); echo "Returned value from the function : $return_value";
  4. Setting different values for Function Parameters: We can set a parameter to have a default value if the function's caller doesn't pass it. $function_holder(); For example. < ?php function printMe($param print $param; printMe("This is test"); printMe(); Dynamic Function Calls: = NULL) It is possible to assign function names as strings to variables and then treat these variables exactly as you would the function name itself. For example: < ?php function sayHello() echo "Hello"; $function_holder = "sayHello";