Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Any one explain to me whats the logic behind this code?

<p>&lt;?php$sample="example";$tranc=&amp;$sample;$tranc="output";echo $sample;echo $tranc;?&gt;output is output output</p>

user-image
Question added by Kamatchi Panneer Selvam , Software Developer , Comtel General Trading LLC
Date Posted: 2014/10/13
Jubayer Arefin
by Jubayer Arefin , Software Developer , Squidoan

=& operator is used to get a reference of a variable. In this case $tranc has a reference of $sample. Try changing the value of $tranc and echo again. You will see the difference.

 

Cheers

Ali Imran
by Ali Imran , Application Development Manager , TekGenisys

$tranc holds address of $sample (i.e. & basically is used for memory address / reference), thus points to what $sample holds, but the3rd statement is an assignment to $tranc so previous pointer wont work.Now echo'ing $sample will output "example", and $tranc will output the word "output".As far the text after closing tags "?>" will simply be output to client application either browser or whatever.

 

 

I hope you understood.

 

regards

More Questions Like This