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!
Problem in reading array element value which has symbol '@'
Moderator: General Moderators
-
rws-piyush
- Forum Newbie
- Posts: 4
- Joined: Fri Nov 26, 2010 6:14 am
Re: Problem in reading array element value which has symbol
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
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
Actually, the @ character is fine when it is within quotation marks. Because it is treated as string.
So, you example:should work.
Please, provide us with the parsing error text and source code
So, you example:
Code: Select all
$aObj = array(
'@test' => 'hello'
);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
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:
I want to read $aObj[0]->@test[0];
Is it possible anyway?
Code: Select all
Array
(
[0] => stdClass Object
(
[@test] => Array
(
[0] => Hi
[1] => Hello
)
)
)Is it possible anyway?
Re: Problem in reading array element value which has symbol
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
Hey....thank a lot!! It works...