php遍历输出数组的方法

php遍历输出数组的方法

实例一:

  1. <html>
  2. <head>
  3. <title>Foreach Demo</title>
  4. </head>
  5. <body>
  6. <?
  7. $list = array("A", "B", "C", "D", "E");
  8. print "<ul>n";
  9. foreach ($list as $value){
  10. print " <li>$value</li>n";
  11. } // end foreach
  12. print "</ul>n";
  13. ?>
  14. </body>
  15. </html>

实例二

  1. <?
  2. $letters[0] = 'A';
  3. $letters[1] = 'B';
  4. $letters[3] = 'D';
  5. $letters[2] = 'C';
  6. foreach ($letters as $letter) {
  7. print $letter;
  8. }
  9. ?>