php: how to get associative array key from numeric

2019-01-10 18:13发布

If I have:

$array = array( 'one' =>'value', 'two' => 'value2' );

how do I get the string one back from $array[1] ?

8条回答
家丑人穷心不美
2楼-- · 2019-01-10 18:53

If you only plan to work with one key in particular, you may accomplish this with a single line without having to store an array for all of the keys:

echo array_keys($array)[$i];
查看更多
小情绪 Triste *
3楼-- · 2019-01-10 18:56

the key function helped me and is very simple

查看更多
登录 后发表回答