Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

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 ajoutée par Kamatchi Panneer Selvam , Software Developer , Comtel General Trading LLC
Date de publication: 2014/10/13
Jubayer Arefin
par 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
par 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