Re: Help with array
| From: | John Thorne | Date: | Mon, 17 Feb 2003 01:29:04 +0000 |
| Subject: | Re: Help with array | ||
| References: | 1 2 3 4 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-25681@lists.php.net to get a copy of this message | ||
$cpt=0; $rownu =1;
while($row = mysql_fetch_row($result))
{
$data[$cpt][0] = $rownu;
$data[$cpt][1] = $row[0];
$data[$cpt][2] = $row[1];
$data[$cpt][3] = $row[2];
$rownu++;
$cpt++;
This worked perfectly
Fredrik..
thank you
jrt
"Fredrik De Vibe" <fredrik@devibe.net> wrote in message
news:ygrd6lrn8ho.fsf@tva.ifi.uio.no...
> john@jrthorne.com (John Thorne) writes:
> [ snip ]
> > $data[$cpt]=
> >
> > $rownu.","."\"".$row[0]."\"".",\"".$row[1]."\","."\"".$row[2]."\"";
>
> This is a string, not an array.
>
> > Could you go a step farther in the $foo[$i][$j] please
>
> $data[$cpt][0] = $rownu;
> $data[$cpt][1] = $row[0];
> $data[$cpt][2] = $row[1];
> $data[$cpt][3] = $row[2];
>
> should do what you want, I guess.
>
> You can have many dimensions in an array. In your case, you have two.
> $foo[][] means that each $foo[] contains another array, where the
> elements of the second dimension can be accessed by $foo[$i][$j] ($i
> and $j being integers and $foo a 2d array).
>
> I don't know how many dimensions you can have in PHP, but I think you
> can have more than two. A three dimensional one will be an array of
> arrays of arrays, accessed with e.g. $foo[$i][$j][$k] ($i, $j and $k
> being integers and $foo a 3d array).
>
> Think of it as an index of books in a library. $foo[$i] contains a 2d
> array of the different sections of the library, $foo[$i][j] contains
> an array of the book shelves in each section and $foo[$i][$j][$k] is a
> book.
>
> Try to google a bit for multidimensional arrays and get a grip on how
> they work. :-)
>
>
> --
> --Fredrik
> "Why be a man when you can be a success?"
> -- Bertold Brecht