Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Array

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
Conny64
Smarty Rookie


Joined: 10 Mar 2016
Posts: 5

PostPosted: Tue Apr 30, 2019 11:11 am    Post subject: Array Reply with quote

Hi,

ich bin leider noch ziemlich am Anfang mit Smarty. Hoffe trotzdem auf Hilfe

Ich möchte Werte einem Array zuweisen und komme irgendwie nicht klar.

Ich schreib mal so wie ich es mir vorstelle:

$adresse[name] "Meier"
$adresse[vorname] = "Franz"
$adresse[ort] = "Köln"

$adresse[name] = "Schulz"
$adresse[vorname] = "Susi"
$adresse[ort] = "Hamburg"

{foreach item=id from=$adresse}
{$adresse.name}, {$adresse.vorname} - {$adresse.ort}
{/foreach}
Back to top
View user's profile Send private message
Conny64
Smarty Rookie


Joined: 10 Mar 2016
Posts: 5

PostPosted: Tue Apr 30, 2019 11:57 am    Post subject: Reply with quote

Ich denke ich habe es selbst hinbekommen.

Wäre es denn richtig wenn ich es so machen würde

Code:


{append var=adress_array value=['name'=>'Meier','vorname'=>'Franz','ort'=>'Köln']}    
{append var=adress_array value=['name'=>'Schulz','vorname'=>'Susi','ort'=>'Hamburg']}   
{foreach from=$adress_array item=adresse}
  {$adresse.name}, {$adresse.vorname} - {$adresse.ort}<br/>
{/foreach}
Back to top
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Tue Apr 30, 2019 12:46 pm    Post subject: Reply with quote

Deine Frage hat in erster Linie wenig mit Smarty, sondern viel mehr mit PHP zu tun.

In der Ersten Frage hast du kein wirkliches Array pro "Nutzer" sondern jeder Wert darin wäre ein Element im Array. Also statt 2 Personen hättest du im ersten Fall 6 Personen.

Schau dir auch das hier an: https://www.php.net/manual/de/language.types.array.php

Im Zweiten Fall machst du es zwar grundsätlich besser/richtig. Aber ich würde abraten "logik" in das Template zu integrieren. Der Aufbau deines Arrays sollte im "backend", also sprich in einer PHP-Datei erfolgen
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP