Skip to content

Instantly share code, notes, and snippets.

@nurullahisik
Last active March 1, 2019 08:02
Show Gist options
  • Save nurullahisik/019de70c75de68cad26af307837c4af9 to your computer and use it in GitHub Desktop.
Save nurullahisik/019de70c75de68cad26af307837c4af9 to your computer and use it in GitHub Desktop.
<?php
// get all php files
$files = glob('*.php');
print_r($files);
/* output looks like:
Array
(
[0] => phptest.php
[1] => pi.php
[2] => post_output.php
[3] => test.php
)
*/
// -----------------------------------------------------------------
// get all php files AND txt files
$files = glob('*.{php,txt}', GLOB_BRACE);
print_r($files);
/* output looks like:
Array
(
[0] => phptest.php
[1] => pi.php
[2] => post_output.php
[3] => test.php
[4] => log.txt
[5] => test.txt
)
*/
// -------------------------------------------------------
$files = glob('../images/a*.jpg');
print_r($files);
/* output looks like:
Array
(
[0] => ../images/apple.jpg
[1] => ../images/art.jpg
)
*/
// ---------------------------------------------------------
$files = glob('../images/a*.jpg');
// applies the function to each array element
$files = array_map('realpath',$files);
print_r($files);
/* output looks like:
Array
(
[0] => C:\wamp\www\images\apple.jpg
[1] => C:\wamp\www\images\art.jpg
)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment