Putting a stop in a foreach

From: Date: Sun, 09 May 2004 14:43:11 +0000
Subject: Putting a stop in a foreach
Groups: php.general 
Request: Send a blank email to php-general+get-185741@lists.php.net to get a copy of this message
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 TIA, Verdon

« previous php.general (#185741) next »