www.pickatutorial.com Computer Tutorials

PHP advanced user defined functions. Free online PHP and MySQL Web Database Programming Tutorial...

Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script
Lessons PHP User Defined Functions 2 Bookmark and Share
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19
Lesson 20
Lesson 21
Lesson 22
Lesson 23
Lesson 24
Lesson 25
Lesson 26
Lesson 27
Lesson 28
Lesson 29
Lesson 30
Lesson 31
Lesson 32
Lesson 33
Lesson 34
Lesson 35
Lesson 36
Lesson 37
Lesson 38
Lesson 39
Lesson 40
Lesson 41
Lesson 42
Lesson 43
Lesson 44
Generally PHP functions are passed arguments by value, this is the default behavior in PHP. PHP also support passing function arguments by reference, and default argument values. If we need to pass an argument to a fuction by reference we must prepend an ampersand (&) to the argument name in the function definition. Consider the following example:

<?php
function add_extra(&$string) {
$string .= 'and this is extra string.';
}
$str = 'This is a string, ';
add_extra($str);
echo $str; // outputs 'This is a string, and this is extra string.
?>
A function in PHP can't return multiple values, but similar result can be obtained by returning an array as shown below:

<?php
function numbers() {
return array (0, 1, 2, 3);
}
?>

To return a reference from a function, we have to use the reference operator & in both the function declaration and when assigning the returned value to a variable as shown in the following example:

<?php
function &returns_ref() {
return $someref;
}
$newref =& returns_ref();
?>



Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.