Carol.Kar
Carol.Kar

Reputation: 5345

Get only files from a folder

I am using PHP 7.4.1.

I am trying to get files from a certain folder and I use the following code for this:

array_diff(scandir($views . "/Text"), array('.', '..'));

I have the following folder structure:

Texts/
├── test1.blade.php
└── Parts

test1.blade.php is a file and Parts is a folder.

The above code gives me back files AND folders.

I would only like to get all .blade.php files in my array.

Any suggestions how to filter out the folder(s)?

Appreciate your replies!

Upvotes: 0

Views: 337

Answers (1)

WinterSilence
WinterSilence

Reputation: 409

  • $result = array_filter($result, 'is_file'); - files
  • $result = array_filter($result, 'is_dir'); - folders

Upvotes: 3

Related Questions