Question: I am trying to show only items that meet a certain criteria in an array. At the moment I am outputting everything in the array.
What I've got so far:

```
$records = $d->get("FoundCount");
$result = array();
for($i = 1; $ <= $record; $i++){

// various array components
$show_published = $d->field(show_published); //this is the variable from the DB that will determine if the item is shown on the page. Yes/no string.

if($show_published == 'Yes'){
 $results[] = new Result(//various array components, $show_published, //more things);
}

```

This seems to output all items, including the ones labeled as `'No'` .

Any guidance would be great. I have only been using php for a few months now.

Answer: 
```
for f in range(0,n):      
    b=f+1
    if ar[f]<ar[b]:

```

Here you referenced an index of a list greater than the length of the list, which is why you got the error. n is the length of the list, so when you add 1 to it for b, it will be an index that doesn't exist. It looks like you might have been aware of this issue happening with this code block:

```
if f==n:
    break

```

However, the program already ran into the error before it got to that point. My solution is to replace n with n-1 in the code above. I am not sure if that fulfills the challenge, I need to read it more thoroughly. Here is what my code looks like. I also got rid of the second code block above because it doesn't do anything. 

```
def birthdayCakeCandles(n, ar):
    j=1
    for f in range(0,n-1):      
        b=f+1
        #if one element is less than the following
        if ar[f]<ar[b]:
            #count the number of elements equal to the following element, add to j
            m=ar[b]
            for k in range(0,n):
                if m==ar[k]:
                j+=1
    return j    

 n = int(input().strip())
 ar = list(map(int, input().strip().split(' ')))
 print(birthdayCakeCandles(n, ar))

```

I also replace j=j+1 with j+=1. Also, the second for loop can be replaced with a list comprehension, but I don't know if you know about them so I left it as it is.

It looks like [this](https://www.hackerrank.com/challenges/birthday-cake-candles/problem) is the challenge you are trying to do, in which case you misunderstood it, and the code above will not work for it. Read it through again and read the example. It is a lot simpler than you think.
```
            else:
                    m=ar[b]
                    for k in range(0,n):
                        if m==ar[k]:
                            j=j+1

```

Is indented incorrectly. It should be: 

```
            else:
                m=ar[b]
                for k in range(0,n):
                    if m==ar[k]:
                        j=j+1

```

Also, 

```
for f in range(0,n):      
        b=f+1
     #   if ar[f]<ar[b]: <-- Your commented out line used to create a new block
            if f==n:   # <-- This line is incorrectly indented as a result
                break (and all lines after)
            else:
                m=ar[b]  # I moved this back in, not a syntax error, but is incorrect. 
                for k in range(0,n):
                    if m==ar[k]:
                        j=j+1

```