Home >php教程 >php手册 >PHP中将文件载入数组

PHP中将文件载入数组

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 11:34:381206browse

使用file()函数将文件载入数组,文件中的每一行作为数组的一个元素。

实例:
array_file.php:

view sourceprint? 01.<?php 02.    $DOCUMENT_ROOT $_SERVER['DOCUMENT_ROOT']; 03.?> 04. 05.     06.        <title>Test Array File</title> 07.     08.     09.        <?php 10.            $peoples = file($DOCUMENT_ROOT.'/test/03/people.txt'); 11.            <code>$count count($peoples); 12.            if (<code>$count == 0) { 13.                echo 'NO peoples pending. Please try again later.'; 14.            } 15.            for ($i = 0; $i <code>$count$i++) { 16.                echo $peoples[$i].'<br>'; 17.            } 18.        ?> 19.     20.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:你不了解PHP的10件事情Next article:PHP实现常见排序