How to pass reference parameters PHP?

PHPServer Side ProgrammingProgramming

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
raja
Published on 13-Oct-2020 07:27:14
Advertisements