0

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?

2
  • missing array in line 1 and ; in line 4 Commented May 24, 2009 at 3:08
  • I've updated the syntax Imran. Commented May 24, 2009 at 5:00

2 Answers 2

6

Use array_keys().

$fields = array(
  'f1' => array('test'),
  'f2' => array('other' => 'values'),
);
$keys = array_keys($fields);
Sign up to request clarification or add additional context in comments.

2 Comments

missing array in line 1 and ; on line 4
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].
0

$fields['f2'][other']

To access it directly

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.