Reputation: 3091
I have an object contained inside an array
array(1) {
["main"]=> object(Profile)#151 (20)
{
["field_first_name"]=> array(1) { ["und"]=> array(1) { [0]=> array(3) { ["value"]=> string(6) "Fred" ["format"]=> NULL ["safe_value"]=> string(6) "Fred" } } }
}
}
I am trying to get the value "Fred" from this array. I thought I could do this
$first_name= $profile['main']->['field_first_name']['und'][0]['value'];
but it didn't work. It actually gave me an error
Parse error: syntax error, unexpected '[', expecting T_STRING or T_VARIABLE or '{' or '$'
What am I doing wrong?
Upvotes: 0
Views: 47
Reputation: 53246
This should fix your error and return the expected value:
$first_name = $profile['main']->field_first_name['und'][0]['value'];
Upvotes: 1
Reputation: 2581
field_first_name is a property of $profile['main'] wich is an object.
$profile['main']->field_first_name;
And the code you added in your example would be like this.
$first_name= $profile['main']->field_first_name['und'][0]['value'];
Upvotes: 4