note 27721 added to ref.array
| From: | wheaty at planetquake dot com | Date: | Tue, 17 Dec 2002 00:34:57 +0000 |
| Subject: | note 27721 added to ref.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-40987@lists.php.net to get a copy of this message | ||
In keeping with OO principles in PHP4, if you want to pass a reference of an array to an object
(instead of using ugly global variables):
==================================
class A
{
var $myarray;
// constructor
function A ( &$array_param )
{
$this->myarray =& $array_param;
}
function put_hi()
{
$this->myarray[] = "Hi!";
}
}
$greetings = array("Hello.", "How are you doing?", "What's up?");
$myobj =& new A($greetings);
$myobj->put_hi();
print_r($greetings);
==================================
Will Output:
Array ([0] => Hello. [1] => How are you doing? [2] => What's up? [3] => Hi!)
--
http://www.php.net/manual/en/ref.array.php
http://master.php.net/manage/user-notes.php?action=edit+27721
http://master.php.net/manage/user-notes.php?action=delete+27721
http://master.php.net/manage/user-notes.php?action=reject+27721