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" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
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
[EMAIL PROTECTED]
-------------------------


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to