Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这个数组:
$foo = array( 'bar1' => 1, 'bar2' => 2 );
现在我想直接获取第二个键的名称。我怎么能不使用next()呢?
next()
$keys=array_keys($foo); echo $keys[1];
如果您只需要一个键并且拥有 PHP 5.4,则可以在一个语句中取消引用它:
echo array_keys($foo)[1];