"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");
>         }
>     }
> }

Why don't you use a for() loop to restrict to 5 loops?:

$count = count($this->_content);
for ($i; $i < 5; $i++) {
...
}

>
> Php doesn't like the syntax on any of the,
> $this->_content[$n] => $item['type']

Because => is a foreach() specific syntax. As far as I understand you don't
need $this->_content[$n] as this is the same as $item, so just omit
'$this->_content[$n] =>':

         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");
         }

Please try and report if it helped.

Regards, Torsten

> , etc lines
>
>
> TIA,
> Verdon

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

Reply via email to