This is a discussion on implode() function within the PHP Language forums, part of the PHP Programming Forums category; I have 2-dimensional array with numeric indices for both dimensions, called $results, which contains the search results from a ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I have 2-dimensional array with numeric indices for both dimensions,
called $results, which contains the search results from a database. The first dimension contains the records, and the second contains the fields. I want to convert it into an XHTML table to echo to the browser. For a 1-dimensional array, I would do this with implode(). Can I use implode() on a 2D array? If not, is there some other function I could use to do this, or will I have to write my own? Or has anyone already written one? |
|
|||
|
On 28 Feb 2005 19:32:25 -0800, "DJ Craig" <spit@djtricities.com>
wrote: >I have 2-dimensional array with numeric indices for both dimensions, >called $results, which contains the search results from a database. >The first dimension contains the records, and the second contains the >fields. I want to convert it into an XHTML table to echo to the >browser. For a 1-dimensional array, I would do this with implode(). >Can I use implode() on a 2D array? I'm honestly surprised you would use implode() to render a 1-dimensional array in XHTML. That's a rather hackish approach to the problem. >If not, is there some other >function I could use to do this, or will I have to write my own? You'll have to write your own, but the problem is pretty trivial. Just iterate both dimensions of the array and print out what you need. |