[英]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: 使用
array_keys
获取密钥:
$keys = array_keys($array);
$key = $keys[0];
$value = $array[$key];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.