Jump to:

23355 Posts in 17734 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Logic error while iterating through for loop

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

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

Page: 1
Go to End
Author Topic: 351 Views
  • Epro95Z28
    Avatar
    Community Member
    4 Posts

    Logic error while iterating through for loop Link to this post

    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

  • Epro95Z28
    Avatar
    Community Member
    4 Posts

    Re: Logic error while iterating through for loop Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: Logic error while iterating through for loop Link to this post

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

    351 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.