Return a reference from a function in PHP

Description

The following code shows how to return a reference from a function.

Example


<?php/*from  www.ja  va  2 s .  co  m*/
  function &getRandArray()
  {
    $a = array();
  
    for($i=0; $i<10; $i++)
    {
      $a[] = rand(1,100);
    }

    return($a);
  }

  $myNewArray = &getRandArray();
  echo $myNewArray;
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Language Basic »




PHP Introduction
PHP Operators
PHP Statements
Variable
PHP Function Create
Exception
PHP Class Definition