Home > Article > Backend Development > PHP loop creation directory example sharing_PHP tutorial
This article mainly introduces the example of php loop creation directory. The principle is to continuously try to create the upper directory, and so on. Friends in need can refer to it
The code is as follows: function mk_dir($dir, $mod = 0777) { if(!is_dir($dir) || mkdir($dir, $mod)) { if(!mk_dir(dirname($dir, $mod))) { Return false; } } Return mkdir($dir, $mod); } Principle: Just keep trying to create upper-level directories, and so on.