简体   繁体   中英

Get key & value from associative array using numeric index

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

Use array_keys to get the keys:

$keys = array_keys($array);
$key = $keys[0];
$value = $array[$key];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM