遍历的问题

1.遍历一个MySQL的结果集  
$result=mysql_query("select * from users");
while ( $row = mysql_fetch_array($result)) {
}
2.读出一个目录中的内容
$dh = opendir('/home/harryf/files');
while (($file = readdir($dir)) !== false)
  {
  echo "filename: " . $file . "<br />";
  }
  closedir($dir);
?>
3.读出一个文本文件的内容,需要这样写:

例子

<?php
$file = fopen("test.txt", "r");

//输出文本中所有的行,直到文件结束为止。
while(! feof($file))
  {
  echo fgets($file). "<br />";
  }

fclose($file);
?> 

输出:

Hello, this is a test file. 
There are three lines here. 
This is the last line.

  

原文地址:https://www.cnblogs.com/fengzhiqiangcaisangzi/p/3461895.html