Dynamic variabel names in Arrays

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kritro
Forum Newbie
Posts: 1
Joined: Sat Nov 03, 2007 5:12 pm

Dynamic variabel names in Arrays

Post by kritro »

I have a php script that makes multiple sql query's that results
multiple datasets that I will use in a graph.

Its set up something like this.


for($i=0; $i<$n; $i++){
sql query runs here n times and produce each time a dataset that looks like.

2007-10-17 3
2007-10-18 4
2007-10-19 2

I want to put each dataset in an Array with diferent name.
I manage to put on dataset it in one array

$ydata[] = $row[1];
$xdata[] = $row[0];

}

but I need one array of every dataset with names that I can recognize
outside the loop, for eks a dynamic variabel name that consist of
$i and some other name.

like $i.$xdata[], but I cant make this work.

Anyone now how to do this I would be very grateful.

kritro
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Code: Select all

${$i.$xdata}[]
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Badness. The logic needs rethinking. i.e. multidimensional array, not multiple one-dimensional arrays.
Post Reply