开发者

difference when using & and not using & [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Reference - What does this symbol mean in PHP?

Hi, I was using like

$formCheckbox = $form->addElement('radio',...);
$formCheckbox->setChecked(true);

this was working on windows properly but was not on linux i.e it was not checking the radio button.

so i changed it like

$formCheckbox = **&**$form->addElement('radio',...);
$formCheckbox->setChecked(true);

so i just used & while creating the element. I just wanted to know how does it mak开发者_如何转开发e a difference. I am using HTML quick forms.


in this case there is not much of a difference, because php handles objects internally as pointers..

but as long as you do not know what & stands for, don't use it..

a short introduction to pointer:

$a = 10; 
$b = &$a; 
$b = 20; 
echo $a; -> 20 

$a = 10; 
$b = $a; 
$b = 20; 
echo $a; -> 10

so with & you only reference to another variable, instead of creating a new one


It is passing the variable as a reference, so that the changes are maintained always.

Check this http://php.net/manual/en/language.references.pass.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜