2

I have an array:

$array = array(
     '001' => '555',
     '002' => '666',
     '003' => '777'
);

I wish to get the key & value using number index

$key = $array[0];
$value = $array[0][];

I am using a number index as the size of the array when executed will be unknown

0

1 Answer 1

7

Use array_keys to get the keys:

$keys = array_keys($array);
$key = $keys[0];
$value = $array[$key];
Sign up to request clarification or add additional context in comments.

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.