0
我正在使用以下代碼搜索文件,但在輸出中顯示結果5次。 這是代碼。如果代碼中有錯誤,則請plz告訴。如何限制在PHP中重複數組?
$root1 = $_SERVER['DOCUMENT_ROOT'];
$directory =
$root1.'/Place4Info/Data/Admin_data/';
$it = new
RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
while($it->valid())
{
if(!$it->isDot())
{
$files =glob($directory.$it->getSubPath().'/*.jpg');
print_r($files);
}
$it->next();
}
&輸出爲: -
Array ([0] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports19.jpg [1] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports21.jpg [2] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports22.jpg [3] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports3.jpg) Array ([0] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports19.jpg [1] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports21.jpg [2] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports22.jpg [3] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports3.jpg) Array ([0] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports19.jpg [1] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports21.jpg [2] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports22.jpg [3] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports3.jpg) Array ([0] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports19.jpg [1] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports21.jpg [2] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports22.jpg [3] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports3.jpg) Array ([0] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports19.jpg [1] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports21.jpg [2] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports22.jpg [3] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports3.jpg) Array () Array ([0] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/pratikg88/matromonial24.jpg)
嘿夥計它不工作,如果我具體添加的文件名 如果我把打印語句在while循環,然後它的工作原理,但再次重複問題發生 – 2010-09-01 08:26:21
@ pritkg88:哦,我現在看到的另一個錯誤,你被清除$文件陣列與每個迭代,請參閱我的編輯 – knittl 2010-09-01 08:28:06
嘿傢伙我知道它會是這樣的 $ i = 0; $ num = 1; while($ it-> valid()and $ i <$ num) if(!$ it-> isDot()){files = glob($ directory。$ it-> getSubPath()。' /*.jpg'); \t \t print_r($ files); \t \t $ i ++; } \t $ it-> next(); } – 2010-09-01 08:32:26