scratch – Blame information for rev
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
87 | office | 1 | <?php |
2 | |||
3 | require_once __DIR__ . '/../vendor/autoload.php'; // Autoload files using Composer autoload |
||
4 | |||
5 | use Fusonic\Linq\Linq; |
||
6 | $files = glob("/tmp/*"); |
||
7 | |||
8 | // Calculate the average filesize of all files greater than 1024 bytes in a directory. |
||
9 | |||
10 | ### Plain PHP: ### |
||
11 | |||
12 | $sum = 0; |
||
13 | $i = 0; |
||
14 | foreach($files as $file) { |
||
15 | $currentSize = filesize($file); |
||
16 | if($currentSize > 1024) { |
||
17 | $sum += $currentSize; |
||
18 | $i++; |
||
19 | } |
||
20 | } |
||
21 | $avg = $sum / $i; |
||
22 | |||
23 | echo "Average: " . $avg; |
||
24 | |||
25 | ### Linq: ### |
||
26 | |||
27 | $avgL = Linq::from($files) |
||
28 | ->select(function($f) { return filesize($f); }) |
||
29 | ->where(function($fs) { return $fs > 1024; }) |
||
30 | ->average(); |
||
31 | |||
32 | echo "<br/><br>Average Linq: " . $avgL; |