Skip to content

Instantly share code, notes, and snippets.

@rahulhaque
Created November 12, 2020 10:10
Show Gist options
  • Save rahulhaque/f204ef187646369c3cc9670dfec4119d to your computer and use it in GitHub Desktop.
Save rahulhaque/f204ef187646369c3cc9670dfec4119d to your computer and use it in GitHub Desktop.
Simple helper function to delete matching files using PHP
<?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