Re: SQ: what does the & sign do

From: Date: Tue, 21 May 2002 13:06:10 +0000
Subject: Re: SQ: what does the & sign do
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-98590@lists.php.net to get a copy of this message
Its a Reference Operator. You can use it to reference variables to one another, like $a = &$b; meaning that anytime you change the value of $a it would change the value of $b.... Used for functions works in the same way. Its a way of improving the scope of a variable. Instead of passing a value to the function and working with that value only in the function, its a reference to a global function and will change the value outside the function. -Adam ----- Original Message ----- From: "Wilbert Enserink" <wilbert@pdd.nl> To: <php-general@lists.php.net> Sent: Tuesday, May 21, 2002 8:32 AM Subject: [PHP] SQ: what does the & sign do Hi all, maybe this is a stupid Q, but lately I'm diving into OOP. Below you can see a piece of example code from the manual. my Q: what does the & sign do in functioncb_modify( &$item,$key) ?? I noticed this sign is used more, so it should be handy, but hwat does it do? thx Wilbert ----------------------------- class mod { var $thearray; function mod( $a ) { $this->thearray = $a; } function cb_modify( &$item, $key ) { $item = "pref_".$item; } function modify() { array_walk( $this->thearray, array( $this, 'cb_modify' ) ); } } $m = new mod(array("one","two","three")); $m->modify(); print_r($m); which prints out: mod Object ( [thearray] => Array ( [0] => pref_one [1] => pref_two [2] => pref_three ) ) ------------------------- Pas de Deux Van Mierisstraat 25 2526 NM Den Haag tel 070 4450855 fax 070 4450852 http://www.pdd.nl info@pdd.nl -------------------------

« previous php.general (#98590) next »