Multi-Dimensional Arrays Help - And Other Questions on Arrays

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fjm
    Contributor
    • May 2007
    • 348

    #76
    Originally posted by Dormilich
    that's what I call professional attitude. you're always welcome.



    wait ’til you see objects… ;)
    Thanks to BOTH of you guys. You guys are fantastic as are alot of the other guys that have helped me so much including Atli and Pbmods. This is a great forum and I sincerley appriciate all the help that you guys continue to extend to me. As if I haven't said it enough. Thanks a lot guys and thanks for sticking with me on this.

    Also.. I kind of have a bad habit of putting the cart before the horse.. I have been using objects for about a year now. Unless your talking about something other than class objects that is. :)

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #77
      Originally posted by fjm
      I have been using objects for about a year now.
      well, I found arrays way easier to understand than objects with all their OOP philosophy attached…

      the prospect of fetching DB data into object arrays is always thrilling…

      Comment

      • fjm
        Contributor
        • May 2007
        • 348

        #78
        Originally posted by Dormilich
        well, I found arrays way easier to understand than objects with all their OOP philosophy attached…

        the prospect of fetching DB data into object arrays is always thrilling…
        lol.. Ah yes.... record. I have been using that for a little while now. See.. for me, arrays were WAY harder to get a real grasp on. It's kind of like this for me.. I have been programming for about a year and a half now and I feel like I have reached a state where I almost feel embarrassed for not understanding arrays that well. I had an opportunity to talk to another PHP programmer the other day and we were talking about objects and I didn't even break a sweat. But when he started talking about arrays, I just cringed. I have no idea why they have been so hard for me. I do know that having my DBAL with the fetch_array set to BOTH didn't help me because I could never seem to figure out exactly what was going on.

        I am not by any means an expert on objects and truly feel that I have grazed the surface but I feel like I write better and cleaner code and that is my #1 priority. The better I can code, the happier I am. :)

        Comment

        • fjm
          Contributor
          • May 2007
          • 348

          #79
          Hey Ciary, are you still with me?

          Comment

          • Ciary
            Recognized Expert New Member
            • Apr 2009
            • 247

            #80
            i'm still with you, but i dont have much to say about objects. i dont know much about them.

            object are to me what arrays were to you :)

            Comment

            • fjm
              Contributor
              • May 2007
              • 348

              #81
              Originally posted by Ciary
              i'm still with you, but i dont have much to say about objects. i dont know much about them.

              object are to me what arrays were to you :)
              That's cool. I still myself don't fully understand them. I still struggle with objects too. :)

              Listen... in your code.. I am getting a foreach error on this line:
              foreach($table['Rows'] as $row)

              I cannt for the life of me, see it. Can you?

              EDIT: Invalid argument supplied for foreach()

              Comment

              • Ciary
                Recognized Expert New Member
                • Apr 2009
                • 247

                #82
                did you correct my 'rows to 'Rows'? if thats not the problem try using $table[1] and see if u still get the problem.

                Comment

                • fjm
                  Contributor
                  • May 2007
                  • 348

                  #83
                  OK, yes, I did originally correct the rows to Rows and that didn't work. I just now tried foreach($table[1] as $row) but now I get an offset error.

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #84
                    post the array, maybe we see something…

                    Comment

                    • Ciary
                      Recognized Expert New Member
                      • Apr 2009
                      • 247

                      #85
                      what do you get if you replace the foreach with this.
                      Code:
                      var_dump[$table]
                      what do you get as output?

                      Comment

                      • fjm
                        Contributor
                        • May 2007
                        • 348

                        #86
                        Ok here is everything that I have so far.

                        Code:
                        $pages = array
                        (
                          array
                          (
                            "Title" => "First page"
                            , "Tables" => array
                            (
                              'a'=>'b',
                              array
                              (
                                "Title" => "First table"
                                , "Rows" => array
                                (
                                  'c'=>'d',
                                  array
                                  (
                                    "e"=>"f",
                                    "Cells" => array
                                    (
                                      "Col1"
                                      , "Col2"
                                      , "Col3"
                                    )
                                  )
                                )
                              )
                            )
                          )
                        );
                        
                        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>";
                          }
                        }

                        Comment

                        • Ciary
                          Recognized Expert New Member
                          • Apr 2009
                          • 247

                          #87
                          if you remove the 'a' => 'b', 'c' => 'd' and 'e' => 'f' it will work

                          Comment

                          • fjm
                            Contributor
                            • May 2007
                            • 348

                            #88
                            Ok, here's my var_dump:
                            Code:
                            array(2) {
                              ["Title"]=>
                              string(11) "First table"
                              ["Rows"]=>
                              array(2) {
                                ["c"]=>
                                string(1) "d"
                                [0]=>
                                array(2) {
                                  ["e"]=>
                                  string(1) "f"
                                  ["Cells"]=>
                                  array(3) {
                                    [0]=>
                                    string(4) "Col1"
                                    [1]=>
                                    string(4) "Col2"
                                    [2]=>
                                    string(4) "Col3"
                                  }
                                }
                              }
                            }

                            Comment

                            • Ciary
                              Recognized Expert New Member
                              • Apr 2009
                              • 247

                              #89
                              solution is posted above :)

                              Comment

                              • fjm
                                Contributor
                                • May 2007
                                • 348

                                #90
                                Got it Ciary. Thanks. I removed them and I no longer have the error but don't have the columns echoing to the browser. Instead, I get the dreaded "Array". :\

                                Comment

                                Working...