Home > Article > Backend Development > PHP array operation to obtain array element index value_PHP tutorial
If we want to quickly obtain the index value by giving a value, we can use the php array_values() function, which can help us find what we want quickly and concisely. Let's take a look at the usage of the array_values() function
The array_keys() function returns a new array containing all the key names in the array.
If the second parameter is provided, only the key name with the key value is returned.
If the strict parameter is specified as true, PHP will use equality comparison (===) to strictly check the data type of the key value.
Grammar
array_keys(array,value) parameter description
array required. Specifies the input array.
value is optional. The index (key) of the specified value.
strict optional. Used with the value parameter. Possible values:
true - Returns the key with the specified value based on the type.
false - the default value. Does not depend on type.
Example 1
The code is as follows
|
Copy code
|
||||
代码如下 | 复制代码 | ||||
$a=array("a"=>"Horse","b"=>"Cat","c"=>"Dog"); 输出: Array ( [0] => c) |
print_r(array_keys($a));
?>
代码如下 | 复制代码 |
$a=array(10,20,30,"10"); 输出: Array ( [0] => 0 [1] => 3 ) |
Array ( [0] => a [1] => b [2] => c )
代码如下 | 复制代码 |
$a=array(10,20,30,"10"); 输出: Array ( [0] => 3) |
The code is as follows |