0

This problem is old and basic but I can't figure out a better way to get it right without looping through the whole array

$a=array(
'a'=>array
    (
      'x'=>'something',
      'y'=>'somethingelse',
      'z'=>'another thing'
    );
);

I would like to get the value of 'y' key.

I try this

foreach($a as $k=>$v)
{
  foreach($v as $vv)
  {
    return $v['y']
  }
}

UPDATE
Thanks for your posts. How stupid I am :shy:

1
  • 4
    I would think this would be as simple as using $a['a']['y']. Commented Feb 10, 2012 at 17:40

1 Answer 1

2
echo $a['a']['y'];

This is me adding characters to reach the 30 char minimum.

Sign up to request clarification or add additional context in comments.

2 Comments

I thought about answering this way (hence my comment above), but it seemed to me there must be more to this problem than meets the eye.
Haha I know, sometimes when the answer is so basic I feel bad posting an answer as it feels like cheap upvote trawling. I usually opt for the comment route myself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.