Call by Reference in PHP

Program 1

<html>
    <head><title>PHP For Loops</title>
    <body>
     <center>
  
<?php

  function swap(&$a,&$b) // copy in local
  {
        $c=$a;
        $a=$b;
        $b=$c;
  }
  // call main
  $a=50;
  $b=30;
  echo "<br> Before Swaping: ".$a." ".$b;  
  swap($a,$b);  // call by value
  echo "<br> After Swaping: ".$a." ".$b;  














    //   function abc(&$n)   //    reference variable $n=15
    //   {
    //       $n=$n+10;
    //   }
     



    //   // Main

    //   $n=5;   //  local variable main  $n=5
    //   abc( $n);  //  call by reference 
    //   echo $n;  // $n
?>
</center>
</body>
</html>

 

courses

Leave a Reply

Your email address will not be published. Required fields are marked *