Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Logic error while iterating through for loop

Go to End

3 Posts   693 Views


Community Member, 4 Posts

25 April 2012 at 2:33am

Hey all I'm getting a "[Notice] Undefined offset: 0" silverstripe error message while trying to go through a for loop

for ($i = 0; $i < count($aStartDate); ++$i) {
$duplicateCount = 0;
//print $aStartDate[$i];
for ($g = 0; $g < count($aStartDate); ++$g) {
if ($aStartDate[$i] == $aStartDate[$g]) {

if ($duplicateCount != 0) {
$dateToReplace = $aStartDate[$i];

The error message shows up on the "if ($aStartDate[$i] == $aStartDate[$g]) {" line.

Help is much appreciated :)


Community Member, 4 Posts

25 April 2012 at 2:53am

What I'm trying to do is go through an array and remove duplicate entries and replace them the amount of entries as a single entry.

The end result is that when there's more than one event happening, it will says "two events". After you click on it, it loads the data for that date (It does an AJAX request based on the StartDate and displays all events)

Confusing? Yeah maybe, losing almost all my hair with this calendar module... blegh


Forum Moderator, 5523 Posts

25 April 2012 at 4:15pm

Perhaps array_count_values() would be easier?