note 16699 added to function.array-push
| From: | thomas dot hoedl at ewave dot at | Date: | Fri, 09 Nov 2001 10:03:51 +0000 |
| Subject: | note 16699 added to function.array-push | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-20634@lists.php.net to get a copy of this message | ||
be carefull about this:
function foo(&$bar) {
global $arr;
array_push($arr,$bar);
$bar = "othervalue";
}
function foo1(&$bar) {
global $arr;
array_push($arr,&$bar); // with '&'!!!!!
$bar = "othervalue";
}
/////////////////
$arr = array();
$bar = "something";
foo($bar);
echo $bar;
echo $arr[0];
//out: othervalue , something
/////////////////
$arr = array();
$bar = "something";
foo1($bar);
echo $bar;
echo $arr[0];
//out: othervalue , othervalue
--
http://www.php.net/manual/en/function.array-push.php
http://master.php.net/manage/user-notes.php?action=edit+16699
http://master.php.net/manage/user-notes.php?action=delete+16699
http://master.php.net/manage/user-notes.php?action=reject+16699