Using array value as key, only the first letter.

Ask about a PHP problem here.
Post Reply
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Using array value as key, only the first letter.

Post by EcazS »

I have a weird issue, I have had this issue before but I can't remember how I solved it. I have this code,

[syntax=php]$this->test = $library["example"];
// test is now an array containing some information

// set key to test
$this->key = "test";

// $items[0] is set to "example"
print_r($this->key[$items[0]]);
[/syntax]
But this does not work, it gives me this error
Warning: Illegal string offset 'example' in C:\wwwroot\EXP\core\class\char.class.php on line 89
t

Notice the trailing "t" at the end of the warning? That is always the first letter of the key, if I change the key to "xp" it gives me "x".

But if I change it to this, then it works.

[syntax=php]
print_r($this->test[$items[0]]);
[/syntax]

How do I solve this?
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: Using array value as key, only the first letter.

Post by EcazS »

Solved.

I by mistake set the variable to a string instead of a variable >_>
Post Reply