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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.