Re: [PHP] Self generating variables/arrays



If eval is the answer, you're asking the wrong question.

You haven't given enough information to really say the best way to do what it
is you're doing. However, I suspect that explode() and arrays of arrays
(i.e., $a[1][2]) will do what you need to do much better than messing around
with eval.

On Sunday 26 November 2006 00:19, jekillen wrote:
Hello;
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.
Thanks in advance
Jeff K

--
Larry Garfield AIM: LOLG42
larry@xxxxxxxxxxxxxxxx ICQ: 6817012

"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson
.



Relevant Pages

  • Re: button scope problem?
    ... > global in scope (unless you fully namespace qualify them to ... > global in your proc will make you happy. ... As I stated, the arrays are global, and I do an 'upvar #0' ... chalk up more bad docs in those texts; otherwise, ...
    (comp.lang.tcl)
  • Re: Global Namespace Variables
    ... :> can be used to bring any namespace into scope. ... :> and all those arrays or variables are in scope. ... create a seperate namespace for seach set of data ...
    (comp.lang.tcl)
  • Re: Converting to capital only one word in a line
    ... On 1/15/07, Jay Savage wrote: ... >> Using scalar() there is redundant as the expression is already in scalar ... $[is the index of the first element of arrays within its lexical ... scope scope. ...
    (perl.beginners)
  • Re: Re : Global Variable
    ... module declaring the variables and arrays you need as PUBLIC? ... Use the public keyword to make sure the scope of the variable ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Re : Global Variable
    ... module declaring the variables and arrays you need as PUBLIC? ... Use the public keyword to make sure the scope of the variable ...
    (microsoft.public.dotnet.languages.vb)