|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
nitroox88 Smarty n00b
Joined: 11 Jan 2021 Posts: 1
|
Posted: Tue Jan 12, 2021 7:09 am Post subject: Hilfe! Array durchlaufen - Werte zurückgeben |
|
|
Hallo zusammen,
danke, dass ich hier sein darf. Heute würde ich mich gerne gleich mit einem Problem an euch wenden. Ich habe ein Array welches ich durchlaufen will um an die einzelnen Werte zu gelangen, vielleicht kann hier jemand helfen?
Das Array :
Code: |
Array (
[30] => Array (
[categories_id] => 30
[categories_status] => 1
[categories_image] => e.jpg
[external_id] =>
[language_code] => de
[categories_name] => Abdrucklöffel
[categories_heading_title] => Abdrucklöffel glatt + perforiert - Rim Lock und Ehricke
[categories_description] =>
[products] => Array (
[products_id] => 30706
[products_quantity] => 10.00
[products_model] => al553
[nr] => 109
[products_image] =>
[products_price] => 389.83
[products_model_cut] => al553
[products_name] => 100 Abdrucklöffel 10er Sets Edelstahl - Rim-Lock perforiert XL-L-M-S-XS
[products_description] =>
)
)
|
Mein Versuch:
Code: | {foreach from=$categories.{$category.categories_id} item=v}
<li>{$categories.products.$v}</li>
{/foreach}
|
|
|
Back to top |
|
Grizzly Smarty Pro
Joined: 15 Apr 2011 Posts: 172 Location: Germany
|
Posted: Wed Jan 13, 2021 8:40 am Post subject: |
|
|
Hey,
kann es sein, dass du ein verschachteltest array hast?
Also so in der Art wie das hier:
Code: |
$cat1 = array("categories_id" => 29,"categories_status" => 1... );
$cat1 = array("categories_id" => 30,"categories_status" => 1... );
$categories = array($cat1, $cat2);
|
Wenn ja, dann kannst du in deinem foreach nicht darüber gehen, denn du müsstest z. B. über $categories.0.categories_id gehen, wobei 0 dann der Index ist.
Außerdem gehst du im for each falsch an die Sache ran. Dein "aktuelles" item, welches den Variabelnamen "v" hat, ist das item welches deine Category darstellt. Also sprich, du müsstest so abfragen:
Code: | <li>{$v.products.0.products_id}</li> |
Wobei auch hier wieder die 0 den Index darstellt. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|