note 101977 added to language.variables.variable

From: Date: Fri, 21 Jan 2011 09:39:36 +0000
Subject: note 101977 added to language.variables.variable
Groups: php.notes 
Request: Send a blank email to php-notes+get-175958@lists.php.net to get a copy of this message
To generate a family of variables, such as $a1, $a2, $a3, etc., one can use "variable variables" as follows: <?php for ($i = 1; $i <= 5; $i++) { ${a.$i} = "value"; } echo "$a1, $a2, $a3, $a4, $a5"; //Output is value, value, value, value, value ?> Note that the correct syntax is ${a.$i} rather than the perhaps more intuitive $a{$i} The dot (.) is the string concatenation operator. A family of variables might be used as an alternative to arrays. ---- Server IP: 69.147.83.197 Probable Submitter: 76.203.127.125 ---- Manual Page -- http://www.php.net/manual/en/language.variables.variable.php Edit -- https://master.php.net/note/edit/101977 Del: integrated -- https://master.php.net/note/delete/101977/integrated Del: useless -- https://master.php.net/note/delete/101977/useless Del: bad code -- https://master.php.net/note/delete/101977/bad+code Del: spam -- https://master.php.net/note/delete/101977/spam Del: non-english -- https://master.php.net/note/delete/101977/non-english Del: in docs -- https://master.php.net/note/delete/101977/in+docs Del: other reasons-- https://master.php.net/note/delete/101977 Reject -- https://master.php.net/note/reject/101977 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#175958) next »