PHP Development-callback-readdir-is_dir-foreach-glob-PhpStorm

Source: Internet
Author: User
Tags glob
* ** Test the folder command and copy the installation directory of a program to the project * traverse all directories and files in the specified directory * readdir () the function returns the file name * is_dir () of the next file in the directory to determine whether the given file name is a directory * readdir print result :. the current directory * readdir prints the result :.. top directory * PHP Development (17)-callback-readdir-is_dir-foreach-glob-PhpStorm

 "; Call_user_func_array (" fun ", array (123,321); // print the result: 123,321, 3 call_user_func_array (" fun ", array (123,321,444,555); // print the result: 123,321,444 function fun ($ one = "1", $ two = "2", $ three = "3") {echo "$ one, $ two, $ three
";}/*** Number of excluded replies * number of replies: in N digits, the 1st digits are the same as the last N digits * strrev reverse string */echo" ---------- callback Demo 2 ----------
"; Demo (25," test "); // print the result: 10 12 13 14 15 16 17 18 19 20 21 23 24 // that is, the number of replies is not printed: 0 1 2 3 4 5 6 7 8 9 11 22 echo"
"; Function demo ($ num, $ n) {for ($ I = 0; $ I <$ num; $ I ++) {if (call_user_func_array ($ n, array ($ I) continue; echo $ I. "" ;}} function test ($ I) {if ($ I = strrev ($ I) return true; else return false ;} /*****/echo "---------- callback Demo 3 ----------
"; // $ Filter = new Filter (); // instantiate Filter // $ filter-> one (1); // call one function in the Filter class // Filter:: two (1); // call the two static function in the Filter class. // use the one function to exclude the integer multiple demo (25, array (new Filter (), "one"); // print the result: 1 2 4 5 7 8 10 11 13 14 16 19 20 22 23 echo"
"; // Static functions two exclude all numeric demos containing string 3 (25, array (" Filter "," two "); // print the result: 0 1 2 4 5 6 7 8 9 10 11 12 15 16 17 18 19 20 21 22 24 echo"
"; Class Filter {function one ($ I) {if ($ I % 3 = 0) {return true;} else {return false ;}} static function two ($ I) {if (preg_match ('/3/', $ I) {return true ;}else {return false ;}}} /*** test the folder command to copy the installation directory of a program to the project * traverse all directories and files in the specified directory * readdir () the function returns the file name * is_dir () of the next file in the directory to determine whether the given file name is a directory * readdir print result :. the current directory * readdir prints the result :.. upper-level directory */echo "---------- opendir ----------
"; $ Dirname ="./demoFile2 "; // open the directory resource $ dir = opendir ($ dirname); // read the echo readdir ($ dir ).'
'; Echo readdir ($ dir ).'
'; Echo readdir ($ dir ).'
'; While ($ file = readdir ($ dir) {$ file = $ dirname. "/". $ file; if (is_dir ($ file) {echo "Directory:" ;}else {echo "file:" ;}echo $ file.'
';} // Close the directory resource closedir ($ dir);/*** test the folder command, copy the installation directory of a program to the project * traverse all directories and files (including subdirectories) in the specified directory) * glob returns the file name or directory matching the specified mode * glob returns an array containing matching files/directories * foreach syntax structure provides a simple way to traverse arrays * foreach (array_expression as $ value) in each loop, the value of the current unit is assigned to $ value and the pointer inside the array moves forward step * (so the next unit will be obtained in the next loop) */echo "---------- opendir2 ----------
"; // FetchDir (" demoFile1 "); function fetchDir ($ dir) {foreach (glob ($ dir. '\ *') as $ file) {echo $ file .'
', "\ N"; if (is_dir ($ file) {fetchDir ($ file) ;}} fetchDir2 ("demoFile1"); function fetchDir2 ($ dir) {foreach (glob ($ dir. '\ *') as $ file) {if (is_dir ($ file) {echo "Directory :". $ file.'
', "\ N"; fetchDir2 ($ file);} else {echo "file:". $ file .'
', "\ N ";}}}

Above is PHP development (17)-callback-readdir-is_dir-foreach-glob-PhpStorm content, more relevant content please pay attention to PHP Chinese network (www.php1.cn )!

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.