tags:

views:

1321

answers:

3
Array ( [kanye] => Array ( [0] => Kanya [1] => Janaye [2] => Kayne [3] => Kane [4] => Kaye ) [wst] => Array ( [0] => ST [1] => St [2] => st [3] => EST [4] => West ) )

Array
(
    [0] => Kanya
    [1] => Janaye
    [2] => Kayne
    [3] => Kane
    [4] => Kaye
)
Array
(
    [0] => ST
    [1] => St
    [2] => st
    [3] => EST
    [4] => West
)

I've got those two arrays inside one array. The top array holds them both, then below is each one individually. When I am displaying the individual arrays, how do I echo their name?

So the first would be kanye, then list the contents, etc.

Hope that makes sense. I know it will be a simple bit of code but it's stumping me.

+7  A: 

It's not exactly clear, what you want to do, but with the foreach statement, you can get the keys:

$outer_arr = array('kanye' => array('Kanya', 'Janaye', 'Kayne', 'Kane'));
foreach($outer_arr as $key => $val) {
    print($key); // "kanye"
    print_r($val) // Array ( [0] => Kanya [1] => Janaye [2] => Kayne [3] => Kane )
}
Török Gábor
That's the one, how could I have forgotten key => val. Thanks!
James
+1  A: 

If you just need to get the keys, you can use array_keys

$myArray = array(
    "Kanye" => array("Kane", ...)
    "West" => array("Wst", ...)
);

print_r(array_keys($myArray));
/*
array (
    0 => Kanye
    1 => West
)
*/
nickf
A: 

How about just print_r on the outer array?

grantwparks