21493 Posts in 5784 Topics by 2622 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 207 Views |
-
Logic error while iterating through for loop

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
-
Re: Logic error while iterating through for loop

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
-
Re: Logic error while iterating through for loop

25 April 2012 at 4:15pm
Perhaps array_count_values() would be easier? http://php.net/manual/en/function.array-count-values.php
| 207 Views | ||
|
Page:
1
|
Go to Top |


