Re: Arrays
| From: | Oyvind Gronnesby | Date: | Tue, 31 Oct 2000 19:18:09 +0000 |
| Subject: | Re: Arrays | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-22989@lists.php.net to get a copy of this message | ||
On Tue, Oct 31, 2000 at 02:34:13PM +0100, Ivanoff Jari wrote:
> I have a script that calls a class that creates graphs.
> The paramaters send to the class is formatted like this:
> $line->y_data['DEF20'] = array(4.896, 4.500, 4.190, 3.050, 2.888, 3.678);
>
> But now i want to feed the data from an other array with 12 fields which I
> get from a database:
> What I would like to know is:
> Can I use an array like this:
>
> I have the following arrays:
> $resulta[] and $goala[]
>
> $line->y_data['XYZ40'] =
> array($resulta[1],$resulta[2],$resulta[3],$resulta[4],$resulta[5],$resulta[6
> ],$resulta[7],$resulta[8],$resulta[9],$resulta[10],$resulta[11],$resulta[12]
> );
>
> or like this:
>
> $line->y_data['ABC10'] = $goala[1-12];
>
> I don't know if this question is very clear but I hope you guys understand
> what I mean!
foreach ($array as $elem) {
$line->y_data['XYZ40'][] = $elem;
}
Whenever you assign something to a variable with the postfix [] you
automatically append it to the end of the array. This loop puts the
elements into the array you were looking for.
If the values are fetched from a database you can i.e. do something like
this:
while ($tmp = mysql_fetch_array($result)) {
$line->y_data['XYZ40'][] = $tmp;
}
The principle is the same. Use [] to append new values.
--
Øyvind Grønnesby
I wonder if there is another word for synonym