Re: Help with array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



$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
ygrd6lrn8ho.fsf@tva.ifi.uio.no">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



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux