if($sizes < 100);
在 if-clause -> empty 语句之后有一个分号。
foreach($results as $item) {
$sizes= filesize($item);
if($sizes < 40*1024) {
echo $item, "\n";
}
}
或者多一点spl / lambda fun + recursion:
<?php
$path = 'c:/temp';
$it = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path),
RecursiveIteratorIterator::LEAVES_ONLY
);
$it = new FooFilterIterator($it, function($e) { return $e->getSize(); }, function($e) { return $e < 40*1024; } );
foreach($it as $f) {
printf("% 6d %s\n", $f->getSize(), $f);
}
class FooFilterIterator extends FilterIterator {
protected $getter;
protected $filter;
public function __construct(Iterator $source, $getter, $filter) {
parent::__construct($source);
$this->getter = $getter;
$this->filter = $filter;
}
public function accept() {
$f = $this->filter;
$g = $this->getter;
return $f( $g($this->current()) );
}
}
还有GlobIterator。