0

For first time I found this problem, see I've a array of objetcs and I access them as follow:

$arrayOfObjects[$pos]->value;

But my problem is that one of the array values have a "-" meaning the value is e-mail so when I do this:

$arrayOfObjects[$pos]->e-mail;

I get an error, how do I handle this? The var can't be changed!!

Reynier
  • 2,340
  • 11
  • 50
  • 88

2 Answers2

4

If you absolutely have to have the hyphens, you can access it like:

$arrayOfObjects[$pos]->{'e-mail'};
kalley
  • 17,364
  • 2
  • 36
  • 35
1

You cannot access a variable with a dash in it in that fashion.

Try this:

$arrayOfObjects[$pos]['e-mail'];
Naftali
  • 142,114
  • 39
  • 237
  • 299