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!
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]
Although its possibly not the most graceful / efficient.. Add this in in the relevant place:
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]