Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   PHP: Kleine Unstimmigkeit mit foreach() (https://www.delphipraxis.net/54570-php-kleine-unstimmigkeit-mit-foreach.html)

alcaeus 6. Okt 2005 17:26


PHP: Kleine Unstimmigkeit mit foreach()
 
Moin allerseits,

ich hab ein kleines Problem mit foreach.
Ich hab z.Zt. folgendes Array:
Code:
$forum_auth_ary = array(
   'auth_view' => $row['auth_view'],
   'auth_read' => $row['auth_read'],
   'auth_post' => $row['auth_post'],
   'auth_reply' => $row['auth_reply'],
   'auth_edit' => $row['auth_edit'],
   'auth_delete' => $row['auth_delete'],
   'auth_sticky' => $row['auth_sticky'],
   'auth_announce' => $row['auth_announce'],
   'auth_vote' => $row['auth_vote'],
   'auth_pollcreate' => $row['auth_pollcreate'],
   'auth_attachments' => $row['auth_attachments'],
   'auth_download' => $row['auth_download']
);
Ueber dieses array laufe ich z.Zt. so drueber:
Code:
foreach ($forum_auth_ary as $name => $value)
{
   $forum_auth_ary[$name] = (isset($_POST[$name])) ? intval($_POST[$name]) : $forum_auth_ary[$name];
   $varname = 'S_'. strtoupper($name);
   $template->assign_var($varname, create_select($select_items, $forum_auth_ary[$name], True, $name));
}
Die erste Zeile stoert mich da ein bisschen. Ich wuerde den neuen Wert gerne in $value schreiben, so dass er nachher auch im array gespeichert ist.
Folgendes laesst PHP aber nicht zu:
Code:
foreach ($forum_auth_ary as $name => &$value)
Hat jemand eine Idee? Notfalls kann ich auch uebers array arbeiten, allerdings waers ueber $value ein bisschen schoener ;)

Greetz
alcaeus

faux 6. Okt 2005 17:44

Re: PHP: Kleine Unstimmigkeit mit foreach()
 
Das geht IMHO nicht, da foreach keine Referenz auf das Array liefert, sondern den Wert einfach per Zuweisung an $value gibt.

Aenogym 6. Okt 2005 17:51

Re: PHP: Kleine Unstimmigkeit mit foreach()
 
das funktioniert leider erst seit PHP5 ;)
(also das mit foreach ($array as $name => &$value) {} )

aenogym

alcaeus 6. Okt 2005 17:52

Re: PHP: Kleine Unstimmigkeit mit foreach()
 
Ok, nachdem das Ding ja auch noch auf PHP4 laufen soll, faellt die Loesung leider weg. Danke trotzdem :)

Greetz
alcaeus

chaosben 6. Okt 2005 18:52

Re: PHP: Kleine Unstimmigkeit mit foreach()
 
Zitat:

Zitat von Aenogym
das funktioniert leider erst seit PHP5 ;)
(also das mit foreach ($array as $name => &$value) {} )

aenogym

Darf ich widersprechen? ;)

alcaeus 6. Okt 2005 18:55

Re: PHP: Kleine Unstimmigkeit mit foreach()
 
Zitat:

Zitat von chaosben
Darf ich widersprechen? ;)

Nein:
Zitat:

As of PHP 5, you can easily modify array's elements by preceding $value with &. This will assign reference instead of copying the value.
Sorry :mrgreen:

Dass mir das nicht aufgefallen ist als ich die Hilfe studiert habe :wall:

Greetz
alcaeus

chaosben 6. Okt 2005 19:03

Re: PHP: Kleine Unstimmigkeit mit foreach()
 
Ach .... ja ..... wer lesen kann ist klar im Vorteil. Sorry. :duck:
Als Entschuldigung hab ich gleich mal für dich gevotet. :)


Alle Zeitangaben in WEZ +1. Es ist jetzt 22:48 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz