See an interview today to write a function that can create a multilevel directory:
My first feeling is to use recursion to create a specific idea as follows:functionDirectory ($dir){if(Is_dir($dir) || @mkdir($dir, 0777)) {//To see if a
$arr= [ ' A ' = ' a ', ' B ' = ' B ', ' c ' = = [ ' d ' = ' d ', ' e ' =[ ' F ' = ' f ', ' g ' =>[' h ' = ' h '] ] ]];//Create an array handler functionfunctionChangeCase ($var,$type=case_upper) {
{Code ...} the output result is as follows: {code ...} my doubt is that when $ count is added to 10, it will not call itself, then it will run the following code $ count -- and the output will end, but why is it still running nine times.
function
The code is as follows:Copy code Class listdir {Var $ depth;Var $ dirname;Var $ list;Var $ tostring;Function listdir ($ dir ){$ This-> dirname = $ dir;$ This-> depth = 0;$ This-> tostring = "";}// Save the result to a multi-dimensional
A function calls itself in its function body called a recursive call. This function is called a recursive function (see this function in the video)function mk ($d =1) {Exportif ($d = = 10) {Echo ' First ', $d, ' Day, there ', ' 1 ', ' dates
1 //phprecursively find if the directory and sub-file names contain Chinese space brackets2 functionSearchdir ($path,&$data){3 if(Is_dir($path)){4 $DP=dir($path);5 while($file=$DP-Read ()) {6 if($file! = '. ' &&$file!
There are several forms of recursive infinite class classification, and here are just a few examples of the three common types:The first type: Returns an array with a sort: '; $result = Gencate ($data);p rint_r ($result); exit; >The second type:
The first method:
Copy Code code as follows:
/**
* Catalog Generation class: Utilsmakedir
* @author Yepeng
* @since 2010.3.18
*/
Class utilsmakedir{
This directory will not be established when the base directory is created for the
This article illustrates the implementation of recursive JSON classes in PHP. Share to everyone for your reference.
The specific implementation code is as follows:
Copy Code code as follows:
/*
* @ anthor:qd
* @ time:2013-09-27
*/
This article illustrates the method of recursively deleting directories and files in PHP. Share to everyone for your reference. The implementation methods are as follows:
I hope this article will help you with your PHP program design.
And it's 3 times times worse than the efficiency. So, the recursion in PHP must be treated with care.
Recently wrote a fast sorting algorithm, found that the recursive efficiency in PHP can not be across, in a variety of servers, may behave
This article illustrates the method of recursive traversal of PHP to delete files. Share to everyone for your reference. Specifically as follows:
This function can be changed to a recursive file copy function with a slight modification
I
create a similar ".. /.. /.. /xxx/xxx.txt "The catalogue is very good!
function Mkdirs ($path, $mode = 0777)//creates directory tree recursively{$dirs = explode ('/', $path);$pos = Strrpos ($path, ".");if ($pos = = False) {//Note:three equal
PHP pays recursive functions, recursive functions are called themselves, these functions are particularly useful for browsing dynamic data structures, such as trees and lists.
Almost no web application requires complex data structures to be
This article describes the method that PHP recursively calls to delete an array of null-value elements. Share to everyone for your reference. Specifically as follows:
The function can delete all null-value elements in an array, including empty
This article brings the content is about the PHP implementation of infinite Pole classification method: Recursive method and reference method, there is a certain reference value, the need for friends can refer to, I hope to help you.
The interview
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.