note 22344 deleted from language.references.whatdo by sniper
| From: | sniper@php.net | Date: | Tue, 30 Sep 2003 01:21:26 +0000 |
| Subject: | note 22344 deleted from language.references.whatdo by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-57327@lists.php.net to get a copy of this message | ||
Note Submitter: ediaz1@NO_SPAMwanadoo.es
----
The ampersand on the function's definitio does matter.
Try this:
----------------------------------------------------
function &crea_modifica_array()
{
static $miarray;
$miarray[1]++;
$miarray[2]++;
return($miarray);
}
$a=&crea_modifica_array();
echo $a[1]," ",$a[2],"<br>";
$b=&crea_modifica_array();
echo $b[1]," ",$b[2],"<br>";
$b[1]++;
echo $a[1];
----------------------------------------------------
It will return
1 1
2 2
3
as you expect.
If you try the above example *without* the ampersand on the function's definition (I mean,
function crea_modifica_array() {...)
the output will be
1 1
2 2
1