Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Say I have a multidimensional array in PHP such as:

this_array= array(
    string_name=>'string', 
    string_array=>array(
        'string_key'=>'string_val'
    )
)

How am I to access string_array's key-val pairs? Is it just:

this_array['string_array']['string_key'] 

Or is it something different?

share|improve this question
7  
Yes, you can access string_val with $arr['string_array']['string_key']. And you could try it before asking. – PLB May 22 '12 at 17:50

1 Answer

up vote 1 down vote accepted

Code should look something like this, if you were intending on using strings as your keys.

$this_array= array(
     'string_name' => 'string', 
    'string_array' => array(
        'string_key' => 'string_val'
    )
);

Yes, you will access it by:

$this_array['string_array']['string_key'];
share|improve this answer
2  
don't forget the semicolon ; – HamZa DzCyberDeV May 22 '12 at 18:45
Ah the darn semicolons :) – David May 22 '12 at 19:00
3  
Semicolons ruined my life. – Andrew Willis May 22 '12 at 19:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.