SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: echo array

  1. #1
    a fresh, new start... dujmovicv's Avatar
    Join Date
    Aug 2006
    Location
    Earth
    Posts
    559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    echo array

    Hi All,

    can someone help me to echo a whole array? This is the first time I work with multidimensional arrays, and I couldn't figure it out yet....

    PHP Code:
    <?
    $table_fields 
    = array (
                    
    "table_name" => array(=> "table_users"=> "table_links"),
                    
    "vartype_1" => array(=> "int"=> "int"),
                    
    "vartype_2" => array(=> "varchar(15)"=> "varchar(350)"),
                    
    "vartype_3" => array(=> "varchar(35)"=> "int(11)"),
                    
    "vartype_4" => array(=> "varchar(35)"=> "varchar(50)"),
                    
    "vartype_5" => array(=> "int(2)"=> "CURRENT_DATE"),
                    
    "field_1" => array(=> "userID"=> "linkID"),
                    
    "field_2" => array(=> "username"=> "url"),
                    
    "field_3" => array(=> "real_name"=> "clicks"),
                    
    "field_4" => array(=> "password"=> "title"),
                    
    "field_5" => array(=> "level"=> "date")
                    );

                    for (
    $i 1$i <= 2$i++)
                        {
         
    // I need to echo the array here I suppose...
                        
    }
    ?>
    Your help is highly appreciated!

    Full time ADMIN - art community
    Part time coder - dsign

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2009
    Location
    nowhere
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use this:

    PHP Code:
    foreach ($table_fields as $a=>$b) {
        foreach (
    $b as $c) {
            echo 
    $c."<br>";
        }

    or

    var_dump($table_fields);

    to show all structure yours table.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2009
    Location
    nowhere
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Am I right? Is that what you mean?

    PHP Code:
    <?
    // yours array $table_fields

    for ($i 1$i <= 2$i++) {
        foreach (
    $table_fields as $a => $b) {
            echo 
    $b[$i]."<br />";
            
    // I need to echo the array here I suppose...
        
    }
    }
    ?>

  4. #4
    a fresh, new start... dujmovicv's Avatar
    Join Date
    Aug 2006
    Location
    Earth
    Posts
    559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 3.grosz View Post
    Am I right? Is that what you mean?

    PHP Code:
    <?
    // yours array $table_fields

    for ($i 1$i <= 2$i++) {
        foreach (
    $table_fields as $a => $b) {
            echo 
    $b[$i]."<br />";
            
    // I need to echo the array here I suppose...
        
    }
    }
    ?>
    Yep, that's correct!
    Thank you for your help man!

    Full time ADMIN - art community
    Part time coder - dsign

  5. #5
    SitePoint Addict
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ... or, if you’re just debugging the array and you don’t need to apply any logic to it:

    PHP Code:
    echo
        
    '<pre>'
        
    print_r$table_fieldstrue )
        . 
    '</pre>'


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •