Created
November 12, 2020 10:10
-
-
Save rahulhaque/f204ef187646369c3cc9670dfec4119d to your computer and use it in GitHub Desktop.
Simple helper function to delete matching files using PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Delete a file or matching files. | |
* | |
* @example deleteFile('/file-path/some-name-*.*'); | |
* | |
* @param string $filename | |
* @return array | |
*/ | |
function deleteFile(string $filename) | |
{ | |
$files = glob($filename); | |
return array_map(function ($item) { | |
return [$item => unlink($item)]; | |
}, $files); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment