array_keys
Returns some or all key names in the array
array_keys()
function returns a new array containing all key names in the array.
If a second parameter is provided, only the key name whose key value is that value is returned.
If the strict parameter is specified as true, PHP uses congruent comparisons ( ===
) to strictly check the data type of the key value.
Returns a new array containing all key names in the array:
<?php $a = array ( "Volvo" => "XC90" , "BMW" => "X5" , "Toyota" => "Highlander" ) ; print_r ( array_keys ( $a ) ) ; ?>
Try it yourself
Use the value parameter:
<?php $a = array ( "Volvo" => "XC90" , "BMW" => "X5" , "Toyota" => "Highlander" ) ; print_r ( array_keys ( $a , "Highlander" ) ) ; ?>
Try it yourself
Use strict parameter (false):
<?php $a = array ( 10 , 20 , 30 , "10" ) ; print_r ( array_keys ( $a , "10" , false ) ) ; ?>
Try it yourself
Use strict parameter (true):
<?php $a = array ( 10 , 20 , 30 , "10" ) ; print_r ( array_keys ( $a , "10" , true ) ) ; ?>
Try it yourself
array_keys ( array , value , strict )
parameter | describe |
---|---|
array | Required. Specify array. |
value | Optional. You can specify a key value, and then only the key name corresponding to that key value will be returned. |
strict |
Optional. Used with the value parameter. Possible values:
|