* Thus wrote Verdon Vaillancourt ([EMAIL PROTECTED]):
> Hi :)
> 
> This is the original statement that works...
> 
> foreach ($this->_content as $item) {
>     if ($item['type'] == 'item'){
> ..

ok. good so far.

> 
> 
> This is my attempt to count items and put a stop in the foreach so it only
> returns 5 items.
> 
> foreach ($this->_content as $n => $item) {
>     if ($n=="5") { 
>         break;
>     } else { 
>         if ($this->_content[$n] => $item['type'] == 'item'){

I'm  not sure why  you  changed all this.

All you have to do is a simple foreach loop with a counter, and
break when the counter reaches your condition:

$need = 5; /* how many we want */

foreach($this->_content as $index => $item) {

  if ($item['type'] == 'item') {
    //...

    /* only decrement if its an 'item' */
    $need--;
  }
  if (! $need) break; /* we got everything we needed */
}


Curt
-- 
"I used to think I was indecisive, but now I'm not so sure."

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to