Web Analytics Made Easy -
StatCounter Passing a Multi Dimensional Array as Parameters - CodingForum

Announcement

Collapse
No announcement yet.

Passing a Multi Dimensional Array as Parameters

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Passing a Multi Dimensional Array as Parameters

    ok, I read a little on this, but its confusing me. Thanks in advance for any help!

    I can loop through the array and echo things out in groups:
    PHP Code:
    <?php

    $menu 
    = array(

          
    'home' => array('akey'    => 'h',
                          
    'title'   => 'bob.org',
                          
    'text'    => 'Home'
                          
    ),

          
    'grant' => array('akey'    => 'g',
                           
    'title'   => 'Overview of Documents to be Filled Out',
                           
    'text'    => 'Request for Grant'
                          
    ),

          
    'timing' => array('akey'    => 't',
                            
    'title'   => 'Overview of Grant Processing Schedule',
                            
    'text'    => 'Time Table'
                          
    ),

    );


    foreach (
    $menu as $mset => $mvalue){
            echo 
    $mset "<br>";;

            foreach (
    $mvalue as $value2){
              echo 
    $value2 ."<br>";
            }
                echo 
    "<hr>";
      }  

    ?>

    But how can I pass these to a function? i.e.:

    PHP Code:
      foreach ($menu as $menuitem) {
        echo 
    fixmenu($menuitem$menuitem['akey'], $menuitem['title'], $menuitem['text'] );
      } 

    Im a little confused at this point, sorry. Thanks in advance for any pointers in the right direction!
    ._-zro
    [email protected]
    zro.redtv.org

    "If HTML and the Web made all the online documents look like one huge book, RDF, schema, and inference languages will make all the data in the world look like one huge database"
    -Tim Berners-Lee, Weaving the Web, 1999

  • #2
    Doh!

    oops! ....i think i got it.
    I think i just screwed the escaping of some characters earlier in other functions.
    heres what i've come up with... i think it works. lemme kno what you think!

    PHP Code:
    <?php

    $menu 
    = array(

          
    'home' => array('akey'    => 'h',
                          
    'title'   => 'bob.org',
                          
    'text'    => 'Home'
                          
    ),

          
    'grant' => array('akey'    => 'g',
                           
    'title'   => 'Overview of Documents to be Filled Out',
                           
    'text'    => 'Request for Grant'
                          
    ),

          
    'timing' => array('akey'    => 't',
                            
    'title'   => 'Overview of Grant Processing Schedule',
                            
    'text'    => 'Time Table'
                          
    ),

    );


    function 
    fixmenu ($name1$akey$title$text) {

             
    $name2 ucfirst($name1);

             
    $item"<li><a href=\"/$name1/\" accesskey=\"$akey\" title=\"$title\">$text</a></li>\n";

             
    $theur $_SERVER['REQUEST_URI'];

             if ( (
    $theur =="/$name1/") or ($theur =="/$name1/index.php") or ($theur =="/$name1")) {
                 
    $item"<li class=\"active\"><a href=\"/$name1/\" accesskey=\"$akey\" title=\"$title\">$text</a></li>\n";
                 }
                 return 
    $item;
    }



    echo 
    "<ul id=\"menu\"> \n";
    foreach (
    $menu as $mset => $mvalue){
          echo 
    fixmenu($mset$mvalue['akey'], $mvalue['title'], $mvalue['text']);
      }
    echo 
    "</ul><!--/menu -->";


    ?>
    ._-zro
    [email protected]
    zro.redtv.org

    "If HTML and the Web made all the online documents look like one huge book, RDF, schema, and inference languages will make all the data in the world look like one huge database"
    -Tim Berners-Lee, Weaving the Web, 1999

    Comment

    Working...
    X