문제

What are the PHP equivalents of .hasNext() and .hasNextLine() in Java? If there is none, how do I detect EOL and EOF? Purpose: Have a file of generic length, but every line has the same format:

string number number

The end product derived from this list is two new text files, one where the lines are ordered after the first number, one where the lines are ordered after the second number.

도움이 되었습니까?

해결책

Enjoy the Filesystem Functions:

다른 팁

file.txt

a
b
c   

php code

$arr = file('file.txt');

$iter = new CachingIterator(new ArrayIterator($arr));
foreach ($iter as $value) {
    var_dump( $iter->hasNext() );
}

output:

bool(true) bool(true) bool(false) 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top