abc

Share This blog with your friends, so that we can improve more & more . our aim is to easy & simple way of learning.

12/15/2020

PHP Function call by value and call by reference

 <?php  

function increment($i)  

{  

    $i++;  

}  

$i = 10;  

increment($i);  

echo $i;  

?>


above function output is 10 



Call by Reference - 


<?php  

function adder(&$str2)  

{  

    $str2 .= 'Call By Reference';  

}  

$str = 'This is ';  

adder($str);  

echo $str;  

?>


above returns output is 'this is call by reference'

use & (ampersand) symbol with formal arguments. The & represents reference of the variable.


No comments:

Post a Comment

An Introduction to the Laravel Framework: What It Is and Why You Should Use It

  If you're a PHP developer looking for a modern, efficient, and powerful framework to build web applications, look no further than Lara...