如果想將同一目錄既檔案按array入面既字眼分類...

編寫、設計網頁與程式。

版主: hamu278, 銘仔

版面規則
  • 本版面亦可以討論網頁寄存公司

如果想將同一目錄既檔案按array入面既字眼分類...

文章Freeman » 2008-11-16, 17:18

例如一個目錄入面有以下咁多個檔案
  • i-circle.com.php
  • al888888.mp3
  • whoami.mdb
  • whoisal888.doc
點樣可以做到按一個array入面既keywords分類?
例如$value = array('i-circle', 'al888');

輸出:
i-circle
---------------------------------------
i-circle.com.php

al888
---------------------------------------
al888888.mp3, whoisal8888.doc

others
---------------------------------------
whoami.mdb
Freeman
地球會員
 
文章: 1680
註冊時間: 2008-06-25, 21:04

Re: 如果想將同一目錄既檔案按array入面既字眼分類...

文章bananasims » 2008-11-16, 17:41

代碼: 選擇全部
$value = array('i-circle', 'al888');
$categorized = array();
$list = array(
   'i-circle.com.php',
   'al888888.mp3',
   'whoami.mdb',
   'whoisal888.doc'
);

foreach($list as $lis) {
   foreach($value as $val) {
      if(strpos($lis, $val) !== FALSE) {
         $categorized[$val][] = $lis;
         break;
      }
   }
}

超級求其,未經測試。
影像.從心 At the heart of the ímage
bananasims
太陽會員
 
文章: 13541
註冊時間: 2005-09-22, 00:00

Re: 如果想將同一目錄既檔案按array入面既字眼分類...

文章Freeman » 2008-11-16, 17:55

駁落去
代碼: 選擇全部
foreach ($categorized as $val)
{
   echo $val . '<br/>';
   echo '---------------------------------<br />';
   foreach ($categorized[$val] as $lis)
   {
      echo implode($lis);
   }
}


輸出左:
i-circle.com.php
---------------------------------

Warning: Invalid argument supplied for foreach() in /test/index.php on line 25
whoisal888.doc
---------------------------------

Warning: Invalid argument supplied for foreach() in /test/index.php on line 25
Freeman
地球會員
 
文章: 1680
註冊時間: 2008-06-25, 21:04

Re: 如果想將同一目錄既檔案按array入面既字眼分類...

文章bananasims » 2008-11-16, 17:57

唔該你唔好亂咁改啦
影像.從心 At the heart of the ímage
bananasims
太陽會員
 
文章: 13541
註冊時間: 2005-09-22, 00:00

Re: 如果想將同一目錄既檔案按array入面既字眼分類...

文章Freeman » 2008-11-16, 17:58

bananasims 寫:唔該你唔好亂咁改啦


:?:
#2果個未有OUTPUT- -'
Freeman
地球會員
 
文章: 1680
註冊時間: 2008-06-25, 21:04

Re: 如果想將同一目錄既檔案按array入面既字眼分類...

文章bananasims » 2008-11-16, 18:00

wait,我自己睇錯野
影像.從心 At the heart of the ímage
bananasims
太陽會員
 
文章: 13541
註冊時間: 2005-09-22, 00:00

Re: 如果想將同一目錄既檔案按array入面既字眼分類...

文章bananasims » 2008-11-16, 18:01

代碼: 選擇全部
foreach ($categorized as $val) {
   echo $val . '<br/>';
   echo '---------------------------------<br />';
   foreach($val as $lis) {
      echo implode('<br />', $lis);
   }
}

睇黎你對 foreach 既用法都唔多熟悉。
影像.從心 At the heart of the ímage
bananasims
太陽會員
 
文章: 13541
註冊時間: 2005-09-22, 00:00

Re: 如果想將同一目錄既檔案按array入面既字眼分類...

文章Freeman » 2008-11-16, 18:08

仲係出同一個ERROR
Freeman
地球會員
 
文章: 1680
註冊時間: 2008-06-25, 21:04

Re: 如果想將同一目錄既檔案按array入面既字眼分類...

文章bananasims » 2008-11-16, 18:11

低能咗添,改咗段 code,你再改返。
viewtopic.php?f=100&p=71246#p71238
影像.從心 At the heart of the ímage
bananasims
太陽會員
 
文章: 13541
註冊時間: 2005-09-22, 00:00

Re: 如果想將同一目錄既檔案按array入面既字眼分類...

文章Freeman » 2008-11-16, 18:14

Warning: implode() [function.implode]: Bad arguments. in /test/index.php on line 37
:oops:

Array
---------------------------------

Warning: implode() [function.implode]: Bad arguments. in /test/index.php on line 37
Array
---------------------------------

Warning: implode() [function.implode]: Bad arguments. in /test/index.php on line 37

Warning: implode() [function.implode]: Bad arguments. in /test/index.php on line 37
Freeman
地球會員
 
文章: 1680
註冊時間: 2008-06-25, 21:04

Re: 如果想將同一目錄既檔案按array入面既字眼分類...

文章bananasims » 2008-11-16, 19:12

print_r 啦你
影像.從心 At the heart of the ímage
bananasims
太陽會員
 
文章: 13541
註冊時間: 2005-09-22, 00:00


回到 [B1] 網頁製作、程式編寫與介面設計



誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 96 位訪客

cron