Jump to content

Array Problem


jaqueson

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.