Hi Torsten, Aidan and Matt

Both of Torsten's and Aidan's suggestions worked, though the number of
returned results using Aidan's method isn't what I expected. This could be
the result of something else and I'm trying to puzzle out why. Matt helped
clarify my basic misunderstanding in what the foreach statement was doing.

Conceptually though, Torsten's and Aidan's suggestions both work.

On 5/9/04 12:11 PM, Torsten Roehr wrote:

> Sorry, I mixed up the for and the foreach syntaxes. Here my (hopefully
> correct) loop proposal:
> 
> for ($i; $i < 5; $i++) {
> 
>    if (is_array($this->_content) && is_array($this->_content[$i]) &&
> $this->_content[$i]['type'] == 'item') {
>      $elements['ITEM_LINK']  = $this->_content[$i]['link'];
>      $elements['ITEM_TITLE'] = $this->_content[$i]['title'];
>      $elements['TARGET']     = $this->_target;
>      $items .= PHPWS_Template::processTemplate($elements, 'phpwsrssfeeds',
> 'block_item.tpl');
>   }
> }
> 
> $elements and items should be initialized before the loop.
> 
>> 
>> Please try and report if it helped.
>> 
>> Regards, Torsten



On 5/9/04 12:11 PM, Aidan Lister wrote:>

> Simple!
> 
> $i = 0;
> foreach ($foos as $foo)
> {
> // do stuff
> 
>   $i++;
>   if ($i > 5) break;
> }
> 
> Cheers
> 
> 
> "Verdon Vaillancourt" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>> Hi :)
>> 
>> I'm trying to put a stop in a foreach statement following the user
>> suggestion here, php.net/manual/en/control-structures.foreach.php
>> 
>> Not really knowing what I am doing, I am running into some synatx
> problems.
>> I'm sure I'm doing something really stupid, can anybody point it out?
>> 
>> This is the original statement that works...
>> 
>> foreach ($this->_content as $item) {
>>     if ($item['type'] == 'item'){
>>         $elements['ITEM_LINK'] = $item['link'];
>>         $elements['ITEM_TITLE'] = $item['title'];
>>         $elements["TARGET"] = $this->_target;
>>         $items .= PHPWS_Template::processTemplate($elements,
>> "phpwsrssfeeds", "block_item.tpl");
>>     }
>> }
>> 
>> 
>> 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'){
>>             $elements['ITEM_LINK'] = $this->_content[$n] => $item['link'];
>>             $elements['ITEM_TITLE'] = $this->_content[$n] =>
> $item['title'];
>>             $elements["TARGET"] = $this->_target;
>>             $items .= PHPWS_Template::processTemplate($elements,
>> "phpwsrssfeeds", "block_item.tpl");
>>         }
>>     }
>> }
>> 
>> Php doesn't like the syntax on any of the,
>> $this->_content[$n] => $item['type']
>> , etc lines
>> 

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

Reply via email to