PHP array_key_first() 函数 完整的 PHP Array 参考手册 实例 获取数组的第一个键值: [mycode3 type='php'] [/mycode3] 执行以上代码,输出结果为: a 定义和用法 array_key_first() 函数用于获取指定数组的第一个键值。 取得指定数组的 array 第一个键值,不会影
(PHP 7 >= 7.3.0)array_key_first— Gets the first key of an arrayDescription array_key_first ( array $array ) : int|string|null Get the first key of the given array without affecting the internal array pointer. Parameters array An array. ...
PHP4PHP5PHP7 不支持 不支持 V7.3.0(含)+支持语法 array_key_first (array $array ) 复制 获取给定数组的第一个键而不影响内部数组指针。 参数 参数必需的描述 array 是 一个数组返回值 如果数组不为空,则返回数组的第一个键; 否则为NULL。 示例...
The PHP array_key_first() function returns the first key of the given array without affecting the internal array pointer.
在PHP 7.3.0 之前,有几种方式可以实现该功能。可以使用 array_keys() 函数,但是性能会比较低。也可以使用 reset() 和key() 函数,但这可能会影响内部数组指针。实现该功能的 polyfill 写法如下: <?phpif (!function_exists('array_key_first')) { function array_key_first(array $arr)...
Return Value: Returns the first key of array if the array is not empty; NULL otherwise. Version: PHP 7.3.0+SyntaxThe basic syntax of the array_key_first() function is given with:array_key_first(array);The following example shows the array_key_first() function in action....
<?php $mixed = [ 10 => 'ten', 'color' => 'blue', 20 => 'twenty' ]; $firstKey = array_key_first($mixed); echo "First key: "; var_dump($firstKey); Despite having string keys later, the function returns the first key (10). The type (int) is preserved in the return ...
在PHP8版本中加入的array_key_first()函数和array_key_last()函数是用于获取数组中第一个键和最后一个键的函数。正如它们的名字所示,array_key_first()将返回数组中第一个键的名称,而array_key_last()将返回数组中最后一个键的名称。这些函数在操作数组时非常有用,因为它们允许我们轻松地访问数组的第一个和最...
<?php // array_key_first() // 返回指定数组中的第一个键值对的键名 $arr = [ 'name'=>'极速教程', 'host'=>'https://www.jisuapi.com/', 'contact'=>'18888888888', 'address'=>'https://www.jisuapi.com/', 'rank'=>'1', 'number'=>1, 6=>'一个特意加进来的数字索引' ]; $res...
To get the first element key in a array we need to use the built-in function in PHP. Here is an example: array_key_first(): Get the first…