foreach - bug?
| From: | Jens Carroll | Date: | Thu, 05 Sep 2002 19:04:11 +0000 |
| Subject: | foreach - bug? | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-5944@lists.php.net to get a copy of this message | ||
Hi all,
I am new to the smarty-list and a smarty newbe. Anyway I tried to do
something simple,
but did not get the result I want.
I will use the smarty doc example to show what went wrong:
<- snipp --------------------------------------------
{* The key contains the key for each looped value
assignment looks like this:
$smarty->assign("contacts", array(array("phone" => "1",
"fax" => "2", "cell"
=> "3"),
array("phone" => "555-4444", "fax" =>
"555-3333", "cell" =>
"760-1234")));
*}
{foreach name=outer item=contact from=$contacts}
{foreach key=key item=item from=$contact}
{$key}: {$item}<br>
{/foreach}
{/foreach}
OUTPUT:
phone: 1<br>
fax: 2<br>
cell: 3<br>
phone: 555-4444<br>
fax: 555-3333<br>
cell: 760-1234<br>
<- snapp --------------------------------------------
This works of course wonderful, but I want to have "only" the 2nd array of
contacts as a result.
so I changed the foreach-statement to:
{foreach name=outer item=contact from=$contacts[1]}
but the result lost its keys and I get:
0: 555-4444
0: 555-3333
0: 760-1234
Any ideas what I'm doing wrong?
Thanks in advace
Jens