如何获取另一个数组内的数组的值[重复]

This question already has an answer here:

I have this:

Array
(
  [28] => Array
    (
        [name] => HTC Touch HD
    )
)

There's only one array inside the main array and I only the value of name. Problem is that I don't know the index (28).

</div>

You could use array_values just in general to get rid of any weird keys:

$normal = array_values($arr);
$normal[0]['name']

Or in this particular case, end, which is only a little bit hacky:

end($normal)['name']

http://codepad.viper-7.com/cApBjK

(Yep, reset and first and such work too.)

You could also just use

$array = array_pop($array);

And then to get the name element:

$array['name']

If you don't know the structure of an array, you can use foreach construct.

You can try something like this:

    reset($outerArray);
    $innerArray = current($outerArray);

Now you should have access to the value you want.

Pretty self-explanatory :)

<?php
$array = array(
    28 => array(
        'name' => 'HTC Touch HD'
    )
);

$key = current(array_keys($array));

echo '<pre>';
print_r($array[$key]);
echo '</pre>';
?>