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,420
  • 11
  • 51
  • 91

2 Answers2

4

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

$arrayOfObjects[$pos]->{'e-mail'};
kalley
  • 18,072
  • 2
  • 39
  • 36
1

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

Try this:

$arrayOfObjects[$pos]['e-mail'];
Naftali
  • 144,921
  • 39
  • 244
  • 303