[ create a new paste ] login | about

Link: http://codepad.org/ftHAnlX2    [ raw code | output | fork ]

IkimashoZ - PHP, pasted on Dec 31:
<?php

  $menu = array(

    array(
      'name' => 'appetizers',
      'items' => array( 'chicken wings', 'fried cheese') 
    ),

    array(
      'name' => 'entrees',
      'items' => array( 'hamburger', 'sirloin steak', 'chicken pot pie' )
    ),

    array(
      'name' => 'deserts',
      'items' => array ( 'cheesecake' )
    ),

  );

  $numGroups = count($menu);

?>
<!doctype html>
<html>

  <head>
    <title>My Restaurant</title>
  </head>

  <body>

    <table>
      <tbody>
        <?php for($g=0; $g<$numGroups; $g++): ?>
        <tr>
          <td><?php echo $menu[$g]['name'] ?></td>
          <?php $numItems = count($menu[$g]['items']) ?>
          <?php for($i=0; $i<$numItems; $i++): ?>
          <?php if($i != 0): ?><tr><?php endif ?>
          <td><?php echo $menu[$g]['items'][$i] ?></td>
        </tr>
          <?php endfor ?>
        <?php endfor ?>
      </tbody>
    </table>

  </body>

</html>


Output:
<!doctype html>
<html>

  <head>
    <title>My Restaurant</title>
  </head>

  <body>

    <table>
      <tbody>
                <tr>
          <td>appetizers</td>
                                        <td>chicken wings</td>
        </tr>
                    <tr>          <td>fried cheese</td>
        </tr>
                          <tr>
          <td>entrees</td>
                                        <td>hamburger</td>
        </tr>
                    <tr>          <td>sirloin steak</td>
        </tr>
                    <tr>          <td>chicken pot pie</td>
        </tr>
                          <tr>
          <td>deserts</td>
                                        <td>cheesecake</td>
        </tr>
                        </tbody>
    </table>

  </body>

</html>


Create a new paste based on this one


Comments: