*bump* Accidentally posted when I wanted to edit. Sorry..
Multi-Dimensional Arrays Help - And Other Questions on Arrays
Collapse
X
-
Code:foreach($pages as $page) { foreach ($page['Tables'] as $table) { foreach ($table['Rows'] as $row) { foreach ($row['Cells'] as $cell) { // see previous post } } } }
Comment
-
OK, thanks. That actually helps me to understand better. Let me ask you this Dormilich.. You say it will take me 3 loops to get there but I count 4 loops. Was the 3 a typo?Comment
-
Ok. I think I understand. I know one thing.. that is that I fee much more comfortable being able to get my data out of a 2D array than before. I am going to have to study this a bit because honestly, it has me baffled a bit.
How long would you say it will take me to get this down; to really learn it? I mean, I totally understand the concept but all of the different arrays has my head spinning. I can't make the mental connection. :)Comment
-
Code:foreach($pages as $page){ echo "<h1>".$page['Title']."</h1><br/>"; foreach($page['tables'] as $table){ echo "<h3>".$table['Title']."</h3><br/>"; echo "<table>"; foreach($table['rows] as $row){ echo "<tr>"; foreach($row as $cell){ echo "<td>".$cell."</td>"; } echo "</tr>"; } echo "</table>"; } }
to understand it wont take long. just try keep practisingComment
-
how long this takes you I can't tell, a good abstraction ability will help shortening it… maybe don't rely too much on the table visualization (if it goes beyond 2D)Comment
-
I think I see something..
Code:$pages = array [B]<-- value[/B] ( array [B]<-- key[/B] ( "Title" => "First page" , "Tables" => array ( 'a'=>'b', array [B]<-- value[/B] ( "Title" => "First table" , "Rows" => array ( 'c'=>'d', array [B]<-- key[/B] ( 'e'=>'f', "Cells" => array [B]<-- value[/B] ( "Col1" , "Col2" , "Col3" ) ) ) ) ) ) );
Comment
-
I truly think I understand this better. Thanks guys! Also Ciary, I used your code and it also worked as did Dormilich's code. What I am going to do now is to study this and make myself some new examples to use. I won't stop until I fully understand them.
Arrays are really cool and I am really beginning to see the benefits of using whenever I can.Comment
-
wait ’til you see objects… ;)Comment
Comment