jaqueson Posted May 27, 2008 Share Posted May 27, 2008 Hi, Ich habe einen Array der assoziativ aufgebaut ist. Wenn ich folgendermassen drauf zugreife funktioniert auch alles. $array['test']; Ich habe aber das Problem, dass ich ueber eine variable auf das array zugreifen muss, d.h. ich muss den namen durch eine variable ersetzten. Ich hab schon alles moegliche probiert, bekomme es aber nicht hin. Hier ein paar versuche: $name = "'test'"; $array[$name]; $array["'".$name."'"]; Kann mir von euch jemand erklaeren wie ich ueber eine Variable auf den array zugreifen kann? Danke im voraus Link to comment https://forums.phpfreaks.com/topic/107462-array-problem/ Share on other sites More sharing options...
The Little Guy Posted May 27, 2008 Share Posted May 27, 2008 English is best: http://www.freetranslation.com/ Link to comment https://forums.phpfreaks.com/topic/107462-array-problem/#findComment-550831 Share on other sites More sharing options...
Psycho Posted May 27, 2008 Share Posted May 27, 2008 I ran your post through a translation and it didn't help much. But, from looking at your code I think the problem is that you are trying to add the single quotes when dynamically referring to the array index. Here are some examples that may help explain <?php $array['test'] = "The array value"; $index1 = "'test'"; $index2 = "'".$name."'"; $index3 = "test"; // NO ' (single quotemarks) echo "Test1: " . $array[$index1] . "<br>"; echo "Test2: " . $array[$index2] . "<br>"; echo "Test3: " . $array[$index3] . "<br>"; //Output //Test1: //Test2: //Test3: The array value ?> Link to comment https://forums.phpfreaks.com/topic/107462-array-problem/#findComment-550915 Share on other sites More sharing options...
The Little Guy Posted May 27, 2008 Share Posted May 27, 2008 Try this: $name = "test"; $array[$name]; Link to comment https://forums.phpfreaks.com/topic/107462-array-problem/#findComment-550926 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.