tags:

views:

209

answers:

2

I have an array that looks like:

$fields = array(
  "f1" => array("test"),
  "f2" => array("other" => "values")
);

I'd like to retrive this information in one array:

$first_dimension = array("f1","f2");

Is there a function in PHP that can extract a particular dimension of an array directly? Is there a syntax shortcut for this?

+6  A: 

Use array_keys().

$fields = array(
  'f1' => array('test'),
  'f2' => array('other' => 'values'),
);
$keys = array_keys($fields);
cletus
missing `array` in line 1 and `;` on line 4
Imran
Look through all other array_ functions - there are a lot of them and they do lots and lots of different things [and generally make your life a lot easier].
Artem Russakovskii
A: 

$fields['f2'][other']

To access it directly

Ben Shelock