想必不少人都會寫幾行甚至幾十行代碼使其列出全部文件變爲數組進行刪除,可是glob函數分分鐘解決問題!php
例子 1
<?php print_r(glob("*.txt")); ?>
輸出相似:
Array ( [0] => target.txt [1] => source.txt [2] => test.txt [3] => test2.txt )
例子 2
<?php print_r(glob("*.*")); ?>
輸出相似:
Array ( [0] => contacts.csv [1] => default.php [2] => target.txt [3] => source.txt [4] => tem1.tmp [5] => test.htm [6] => test.ini [7] => test.php [8] => test.txt [9] => test2.txt )
刪除目錄下全部文件
array_map('unlink', glob('*'));