![]() |
[PHP] Globale Variablen
Morgen.
Noch ein Problem mit PHP. Ich habe grade folgendes probiert:
Code:
Was bekomme ich? Natürlich eine leere Ausgabe. Wäre sonst auch zu leicht gewesen. ;)
global $blubb;
function foo() { $blubb["abc"]="wuppdi"; } function bar() { echo($blubb["abc"]); } foo(); bar(); Was mache ich da falsch? Welche Einstellung verbockt das? Wenn ich statt $blubb["abc"] schreibe $GLOBALS["blubb"]["abc"] geht es seltsamerweise. |
Re: [PHP] Globale Variablen
Es muss heißen:
Code:
Die Variable wird nicht als global "markiert"/gesetzt, sondern in der Funktion als global angesehen (so in etwa).
function foo() {
global $blubb; $blubb["abc"]="wuppdi"; } function bar() { global $blubb; echo($blubb["abc"]); } foo(); bar(); Zitat:
Die Variable wird in dem Fall als global "markiert"/gesetzt. mfG, titus |
Re: [PHP] Globale Variablen
Aaah... Klingt fast logisch. :lol:
Danke. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:31 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 by Thomas Breitkreuz