Page 1 of 1

Problem in reading array element value which has symbol '@'

Posted: Fri Nov 26, 2010 6:21 am
by rws-piyush
I've an array like follows:
$aObj = array(
'@test' => 'hello'
);

I want to read value of $aObj['@test'] but it's giving me a parsing error.

Is there any solution to overcome to this issue?
Thanks in advance!

Re: Problem in reading array element value which has symbol

Posted: Fri Nov 26, 2010 6:47 am
by Celauran
Yeah, don't use @. @ has special meaning in PHP; it tells the interpreter to suppress any errors that would be generated.

Re: Problem in reading array element value which has symbol

Posted: Fri Nov 26, 2010 6:55 am
by rws-piyush
Actually I'm working with some API codes and the return result array gives me some values with @ which I exactly want to store into the database.

Re: Problem in reading array element value which has symbol

Posted: Fri Nov 26, 2010 9:04 am
by awebtech
Actually, the @ character is fine when it is within quotation marks. Because it is treated as string.

So, you example:

Code: Select all

	$aObj = array(
		'@test' => 'hello'
	);
should work.

Please, provide us with the parsing error text and source code :)

Re: Problem in reading array element value which has symbol

Posted: Mon Nov 29, 2010 6:09 am
by rws-piyush
ok, I'm sorry that I had not described the exact problem in my original post. Here is what I want to get from an array $aObj:

Code: Select all

Array
(
    [0] => stdClass Object
        (
            [@test] => Array
                (
                    [0] => Hi
                    [1] => Hello
                )
        )
)
I want to read $aObj[0]->@test[0];
Is it possible anyway?

Re: Problem in reading array element value which has symbol

Posted: Mon Nov 29, 2010 7:53 am
by Weirdan

Code: Select all

var_dump($aObj[0]->{"@test"}[0]);

Re: Problem in reading array element value which has symbol

Posted: Mon Nov 29, 2010 8:01 am
by rws-piyush
Hey....thank a lot!! It works...