dqwh0109 2013-02-13 00:02
浏览 26

从Chunked Array返回唯一值

I have a calendar script that outputs to a text file. I'm opening the text file, reading it into an array and then outputting the results. The text file contains:

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,
*-*

My PHP code looks like this:

$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>";
            }

Problem is, if there is a duplicate entry in the $content_chunked[$i][1] (which is the title in this case), I just want to display it once instead of twice. Is this possible? I thought array_unique might work but it didn't seem to help. Thanks in advance!

  • 写回答

2条回答 默认 最新

  • duanke8011 2013-02-13 00:26
    关注

    array_unique() RETURNS the array without duplicates, but does NOT modify the original array!

    so:

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

    The new array needs to be saved in a variable for you to access it later.

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

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向