...

View Full Version : the global



runeveryday
03-03-2010, 07:56 AM
<?php
function test() {
global $a;
unset($a);
}

$a = 1;
test();
print $a;
?>

why print $a;there is a result,but in the function test() i did unset($a); :confused:,any tips would be appreciated.

Dormilich
03-03-2010, 08:13 AM
any tips would be appreciated.

probably not what youíre looking for Ö donít use globals at all.

runeveryday
03-04-2010, 07:02 AM
why not use global? if you want to use a variable which declare out of a function,you must use it,but i don't know the difference of the $var1=&$var2 and the $var1=$var2

Dormilich
03-04-2010, 07:31 AM
either use the $GLOBALS array (a superglobal), or objects (need a different design).

the & in this case denotes a reference (similar to a pointer in C)

runeveryday
03-04-2010, 09:44 AM
sorry,i am still in confused.

Dormilich
03-04-2010, 10:26 AM
sorry,i am still in confused.

about what?

runeveryday
03-04-2010, 11:27 AM
why $var1=&$var2 doesn't work and $var1 =& $GLOBAL['var2'] can,what the difference between the two ?thank you very much.

Dormilich
03-04-2010, 11:30 AM
an explanation (http://www.php.net/manual/en/language.references.php)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum