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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rws-piyush
Forum Newbie
Posts: 4
Joined: Fri Nov 26, 2010 6:14 am

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

Post 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!
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Problem in reading array element value which has symbol

Post by Celauran »

Yeah, don't use @. @ has special meaning in PHP; it tells the interpreter to suppress any errors that would be generated.
rws-piyush
Forum Newbie
Posts: 4
Joined: Fri Nov 26, 2010 6:14 am

Re: Problem in reading array element value which has symbol

Post 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.
User avatar
awebtech
Forum Newbie
Posts: 21
Joined: Sun Nov 07, 2010 4:54 pm
Location: Russian Federation

Re: Problem in reading array element value which has symbol

Post 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 :)
rws-piyush
Forum Newbie
Posts: 4
Joined: Fri Nov 26, 2010 6:14 am

Re: Problem in reading array element value which has symbol

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Problem in reading array element value which has symbol

Post by Weirdan »

Code: Select all

var_dump($aObj[0]->{"@test"}[0]);
rws-piyush
Forum Newbie
Posts: 4
Joined: Fri Nov 26, 2010 6:14 am

Re: Problem in reading array element value which has symbol

Post by rws-piyush »

Hey....thank a lot!! It works...
Post Reply