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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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   888 Views

Avatar
Epro95Z28

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]) {
$duplicateCount++;
}

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

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

Help is much appreciated :)

Avatar
Epro95Z28

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

Avatar
Willr

Forum Moderator, 5523 Posts

25 April 2012 at 4:15pm

Perhaps array_count_values() would be easier? http://php.net/manual/en/function.array-count-values.php