This is a discussion on Classes & 2 Dim Array Help within the PHP General forums, part of the PHP Programming Forums category; I need to do some screen scraping and I am playing with a table object. I would like to iterate ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I need to do some screen scraping and I am playing with a table object. I would like to iterate through a table in the syntax of $table->tr->td or $table->tr[$i]->td[$j] I Guess. The problem is initializing my $td array. I seem to get erroneous initialization values. How do I do this simple test properly ? Can I skip the $td declaration ? Something seems wrong about that. Thanks in advance. #### table object #### <? Class Table { var $tr = array("td" => array()); function testFill() { $this->tr[0]->td[0] = "col1"; $this->tr[0]->td[1] = "col2"; $this->tr[1]->td[0] = "val1"; $this->tr[1]->td[1] = "val2"; } function Table () { $this->testFill(); } } ?> #### program #### <? include ("class.Table.php"); $table = new Table(); while (list($key,$row) = each($table->tr)) { echo "$key = " . $row->td[0] . "\n"; echo "$key = " . $row->td[1] . "\n"; } ?> #### erroneous output ######### td = td = 0 = col1 0 = col2 1 = val1 1 = val2 |