2013-02-13 4 views
0

텍스트 파일로 출력하는 달력 스크립트가 있습니다. 텍스트 파일을 열고 배열로 읽어 들인 다음 결과를 출력합니다. 텍스트 파일에는 다음이 포함 content_chunked $에서 중복 된 항목이있을 경우청크 배열에서 고유 값 반환

$content = file('DC_PictureCalendar/admin/database/cal2data.txt'); 
$content_chunked = array_chunk($content, 6); 
      if (count($content_chunked > 0)) 
      { 
       echo "<table>"; 
       for ($i=0;$i<count($content_chunked);$i++) 
       { 
        echo "<tr>"; 
        echo "<td valign='top'>"; 
        echo "<div style='padding-top:6px;'>"; 
        echo "<a href='schedule.php'>"; 
        echo "<img src='DC_PictureCalendar/admin/database/images/".$content_chunked[$i][3]."' width='80' height='80' border='2'>"; 
        echo "</a>"; 
        echo "</div>"; 
        echo "</td>"; 
        echo "<td valign='top'>"; 
        echo "<div style='padding-left:5px;'>"; 
        echo "<table>"; 
        echo "<tr>"; 
        echo "<td>"; 
        echo "<h2>"; 
        echo "<a href='schedule.php'>"; 
        echo $content_chunked[$i][1]; 
        echo "</a>"; 
        echo "</h2>"; 
        echo "</td>"; 
        echo "</tr>"; 
        echo "<tr>"; 
        echo "<td>"; 
        echo $content_chunked[$i][2]; 
        echo "<a class='green' href='schedule.php'>"; 
        echo "Read more.."; 
        echo "</a>"; 
        echo "</td>"; 
        echo "</tr>"; 
        echo "</table>"; 
        echo "</div>"; 
        echo "</td>"; 
        echo "</tr>"; 
       } 
       echo "</table>"; 
      } 

문제가있다 [$ i가] [1] (어떤이있다 :

7/9/2013-7/13/2013 
Hot Stuff 
By Robert More. Yes, folks, it's all platform shoes, leisure suits.. 
hotstuff.jpg 
1,1,0, 
*-* 
7/16/2013-7/20/2013 
Hot Stuff 
By Robert More. Yes, folks, it's all platform shoes, leisure suits.. 
hotstuff.jpg 
1,1,0, 
*-* 

내 PHP 코드는 다음과 같습니다 제목이이 경우), 나는 단지 두 번 대신 한 번 표시하고 싶다. 이것이 가능한가? array_unique가 작동한다고 생각했지만 도움이되지 않았다. 미리 감사드립니다!

답변

0

array_unique() 중복 되풀이하지 않고 원래 배열을 수정하지 마십시오!

그렇게 :

$a = [1, 1, 2, 3] 
array_unique($a) => [1, 2, 3] 
$a => [1, 1, 2, 3] 

새로운 배열은 나중에 액세스 할 수있는 변수에 저장해야합니다. 비록

$a = [1, 1, 2, 3] 
$b = array_unique($a) 
$b => [1, 2, 3] 
0

의 가능성이없는 효율적인/가장 우아한 .. 관련 장소에서 이것을에 추가 : 그것은 단지 제목의 중복을 다루는

echo "<table>"; 
$titles = array(); 
for ($i=0;$i<count($content_chunked);$i++) 
{ 
     if (in_array($content_chunked[$i][1], $titles)) continue; 
     $titles[] = $content_chunked[$i][1] 
+0

- 날짜가 다른 여부에 대한 걱정없이. – dotbill

+0

헤이의 도트볼. 작동하지 않는 것 같습니다. 어떻게 실제로 제목을 출력합니까? – soc

+0

for 루프의 바깥 쪽 - var_dump ($ titles); titles 배열에 무엇이 있는지보기 – dotbill