Returning Values by Reference : Return Value « Functions « PHP

Returning Values by Reference

class myclass { 
    private $thevalue; 
    private $theword; 

    public function __construct (){ 
        $num_args = func_num_args(); 
        if($num_args > 0){ 
            $args = func_get_args(); 
            $this->theword = $args[0]; 
    public function setvalue ($newvalue){ 
        $this->thevalue = $newvalue; 
    public function getvalue () { 
        return $this->thevalue; 
    public function getword () { 
        return $this->theword; 
$myclass1 = new myclass ("A"); 
$myclass1->setvalue (1); 

$myclass2 = new myclass ("B"); 
$myclass2->setvalue (2); 

$myclass3 = new myclass ("C"); 
$myclass3->setvalue (3); 

$myclass4 = new myclass ("D"); 
$myclass4->setvalue (4); 

$classarr = array ($myclass1,$myclass2,$myclass3,$myclass4); 

function &findclass ($whichclass,$classarr){ 
    for ($i = 0; $i < count ($classarr); $i++){ 
        if ($classarr[$i]->getvalue() == $whichclass){ 
            return $classarr[$i]; 
$myobject = new myclass (""); 
$myobject =& findclass (3,$classarr); 
echo $myobject->getword(); 

Related examples in the same category

1.Function return more than one value
2.Math Function Library
3.A Function That Returns a Value
4.Function Requiring Two Arguments
5.A Function That Returns a Value
6.Functions that return true or false
7.Returning a value from a function
8.Returning an array from a function
9.Returning a list an array from function
10.Returning a Value by Reference
11.Returning by Reference
12.Returning More Than One Value
13.Multiple return statements in a function
14.return multiple values from a function
15.Using an array returned from a function
16.Passing Arguments and Returning Values by Reference
17.User-Defined Function to Determine a Leap Year