Call By Value
In this method, only values of actual parameters are passing to the function. So there are two addresses stored in memory. Making changes in the passing parameter does not affect the actual parameter.
Example
- <?php
- function increment($var){
- $var++;
- return $var;
- }
- $a = 5;
- $b = increment($a);
- echo $a;
- echo $b;
- ?>
Call by Reference
In this method, the address of actual parameters is passing to the function. So any change made by function affects actual parameter value.
Example
- <?php
- function increment(&$var){
- $var++;
- return $var;
- }
- $a = 5;
- $b = increment($a);
- echo $a;
- echo $b;
- ?>