Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #5315
| From | "Leonardo Azpurua" <leonardo@exmvps.org> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Doubt regarding an array of references... |
| Date | 2012-04-02 11:47 -0430 |
| Organization | A noiseless patient Spider |
| Message-ID | <jlcjem$rrb$1@dont-email.me> (permalink) |
Hi, I am coding a simple parser, where a construct is made of a fixed number sequence of varIDs or quoted literals that may or may not be separated by punctuators. In order to avoid a repetition of similar statements, I decided to try if I could store the references of the variables where each value should be stored and then perform a loop in order to extract and store the symbols. The try was this little program: $a = $b = $c = "nil"; echo "a = $a, b = $b, c = $c<br>\n"; $d = array(&$a, &$b, &$c); for ($n = 0; $n < count($d); $n++) $d[$n] = $n; echo "a = $a, b = $b, c = $c<br>\n"; for ($n = 0; $n < count($d); $n++) $d[$n] = ($n + 100); echo "a = $a, b = $b, c = $c<br>\n"; $n = 200; foreach ($d as &$nx) $nx = $n++;; // why &$nx ? echo "a = $a, b = $b, c = $c<br>\n"; The output is this: a = nil, b = nil, c = nil a = 0, b = 1, c = 2 a = 100, b = 101, c = 102 a = 200, b = 201, c = 202 so it works as needed. My question is regarding the instruction with the comment. My first try was to write foreach ($d as $nx), since each element in the $d array is supposed to be already holding a reference. I find this confusing. Wouldn't &$nx holde the reference to the array element, instead of the reference contained within the array element? Thanks in advance. --
Back to comp.lang.php | Previous | Next — Next in thread | Find similar | Unroll thread
Doubt regarding an array of references... "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-04-02 11:47 -0430
Re: Doubt regarding an array of references... "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2012-04-03 11:02 +0200
Re: Doubt regarding an array of references... "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-04-03 13:39 +0200
Re: Doubt regarding an array of references... Jerry Stuckle <jstucklex@attglobal.net> - 2012-04-03 08:03 -0400
Re: Doubt regarding an array of references... "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-04-03 14:15 +0200
Re: Doubt regarding an array of references... "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-04-04 10:48 +0200
csiph-web