PHP get directory All files with all directories saved to array program _php tutorial

Source: Internet
Author: User
Tags glob
PHP get directory All files with all directories saved to the array program This is a use of the Glob function to save all files and folders in the specified directory to the data, and then we then use a foreach again to determine the relevant data in the same OH.

PHP Tutorial Get directory All files with all directories saved to array program
This is a use of the Glob function to save the specified directory of all files and folders to the data, and then we then use a foreach to save the relevant data in the same OH.

$dirs = Array ();
foreach (Glob ("./*") as $d)
{
$tmp = Explode ('. ', $d);
$k = End ($tmp);
if (Is_file ($d) && $k = = ' php ')
{
$dirs [] = $d;
}
}
Print_r ($dirs);

Show directory all directories

$v =array ();
foreach (Glob ("./*") as $VV)
{
$tmp = Explode ('. ', $d);
$k = End ($tmp);
if (Is_dir ($VV))//directory and file difference is to use Is_dir or is_file to judge
{
$v [] = $VV;
}
}
Print_r ($v);

/*
Results

Array
(
[0] = =./1.php
[1] = =./10.php
[2] = =./11.php
[3] = =./3.php
[4] = =./4.php
[5] = =./5.php
[6] = =./7.php
[7] = =./8.php
[8] = =./9.php
)

Array
(
[0] = =./www.bkjia.com
)
*/


http://www.bkjia.com/PHPjc/445444.html www.bkjia.com true http://www.bkjia.com/PHPjc/445444.html techarticle php get directory All files with all directories saved to the array program This is a use of the Glob function to the specified directory of all files and folders to the data, and then we then use the foreach again to judge ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.