Re: [PHP] Self generating variables/arrays
- From: ceo@xxxxxxxxx ("Richard Lynch")
- Date: Sun, 26 Nov 2006 11:40:40 -0600 (CST)
On Sun, November 26, 2006 12:19 am, jekillen wrote:
I am writing some code that will format results of a search for
display.
I need to split an array into several different arrays but I won't
know
before hand how many, so, I am looking for a way to dynamically
generate arrays for this purpose.
My present direction is to use the following code:
for($i = 0; $i < $c; $i++)
{ eval('$a_'.$i.' = array();'); }
Where '$c' is the derived number of arrays need to hold the
pieces of the bigger array. My confusion, though, is; since
these are created in the scope of the for loop, I don't know
if I can use them elsewhere in the code. The Global statement
sends them outside the scope of the function this code is in,
or does it? And I'm not even sure I am on the right track.
Perhaps someone can say yay or nay on the spot, if not
I can go back and do some experimenting.
PHP has only 2 places where "scope" changes:
#1 global "script" scope
#2 function [name] () { [scope change] }
Obviously, class properties are also bound to the class...
All of this is moot, however, as you are working WAY to hard to
pre-define the arrays.
PHP is quite happy to have you just do:
$a[7][13] = 42;
And it will define the arrays needed to make it work.
Using 'eval' here is DEFINITELY the right answer to the wrong
question. :-)
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
.
- References:
- Self generating variables/arrays
- From: jekillen
- Self generating variables/arrays
- Prev by Date: Re: [PHP] Negative memory_get_usage() Values
- Next by Date: Re: [PHP] Negative memory_get_usage() Values
- Previous by thread: Re: [PHP] Self generating variables/arrays
- Next by thread: PHP sendmail proxy (using xinetd)
- Index(es):
Relevant Pages
|