www.webdeveloper.com
Results 1 to 2 of 2

Thread: for loop

  1. #1
    Join Date
    Nov 2008
    Posts
    61

    for loop

    Hi!
    I need help with for.
    I built a web page structured in this way: I have a div that contains three columns.
    I have an array that contains a list of items that I place inside of my columns.
    what I can not do is build a for loop to place the elements as in the example below.

    <div>
    <div id="column1">
    item 1
    item 4
    </div>
    <div id="column2">
    item 2
    item 5
    </div>
    <div id="column3">
    itemt 3
    item 6
    </div>
    </div>

    Thanks for help..

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,178
    PHP Code:
    $output = array();
    $counter 0;
    foreach(
    $data as $value) {
      
    $output[$counter++ % 3][] = $value;
    }
    foreach(
    $output as $column) {
      echo 
    "<div>";
      foreach(
    $column as $value) {
        echo 
    "<p>$value</p>";
      }
      echo 
    "<div>";

    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles