reference.php

<?php
/* This function returns twice its argument, but leaves
 * original value unchanged since call is by value.
 */
function twice( $x ) {
  $x *= 2;
  return $x;
}

/* This function returns no value.  It uses call by reference
 * to double its argument.
 */
function double( &$x ) {
  $x *= 2;
}
?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Function example</title>
    <meta charset="utf-8">
  </head>
  <body>
    <?php
    $x = 3;				// original value of x
    print "x = $x<br />";		// print it to see
    print "2x=" . twice($x) . "<br />"; // print 2x but leave x unchanged
    print "x = $x<br />";		 // show that x is unchanged
    double($x);				 // now double x for real
    print "x = $x<br />";		 // show that x is doubled
    ?>
  </body>
</html>