Wadih M.
Wadih M.

Reputation: 13462

PHP arrays: extract one dimension

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?

Upvotes: 0

Views: 458

Answers (2)

Ben Shelock
Ben Shelock

Reputation: 20965

$fields['f2'][other']

To access it directly

Upvotes: 0

cletus
cletus

Reputation: 625057

Use array_keys().

$fields = array(
  'f1' => array('test'),
  'f2' => array('other' => 'values'),
);
$keys = array_keys($fields);

Upvotes: 6

Related Questions