How to pass reference parameters PHP?


In PHP, use &$ in function parameter to pass reference parameters.

Example

The PHP code is as follows

 Live Demo

<!DOCTYPE html>
<html>
<body>
<?php
function referenceDemo(&$number){
   $number=$number+100;
   return $number;
}
$number=900;
echo "The actual value is=",$number,"<br>";
$result=referenceDemo($number);
echo "The modified value is=",$result;
?>
</body>
</html>

Output

This will produce the following output 

The actual value is=900
The modified value is=1000

Updated on: 13-Oct-2020

431 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements