【发布时间】:2017-04-28 19:36:00
【问题描述】:
<?php
$new = array("12", "11", "10", "9", "8", "7", "6", "5", "4");
$old = array("10", "9", "8", "7", "6", "5", "4", "3", "2", "1");
$result = array_diff($new, $old);
print_r($result);
?>
结果是
Array ( [0] => 12 [1] => 11 )所以12 and 11根据这个例子,如何在 PHP 中使用 array_diff 处理 (.txt) 文件?
以下是 (.txt) 示例:
新建 (.txt) 文件
Something here12
Something here11
Something here10
Something here9
Something here8
Something here7
Something here6
Something here5
Something here4
Something here3
旧 (.txt) 文件
Something here10
Something here9
Something here8
Something here7
Something here6
Something here5
Something here4
Something here3
Something here2
Something here1
输出 (.txt) 文件
Something here12
Something here11
【问题讨论】:
-
将文件读入数组,然后对它们使用array_diff...
-
array_diff(file('new.txt'), file('old.txt'));就是这样......
标签: php array-difference