Learning PHP
Advanced PHP
PHP Function Reference
PHP Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM
|
PHP Function array_keys()
Syntax
array_keys ( $input [, $search_value [, $strict]] );
|
Definition and Usage
Returns the keys, numeric and string, from the input array. If the optional search_value is specified, then only the keys for that value are returned. Otherwise, all the keys from the input are returned.
Paramters
Parameter | Description |
input | Required.Specifies an array. |
search_value | Required. You can specify a value, then only the keys with this value are returned. |
strict | Optional. Used with the value parameter. Possible values:
* true - Returns the keys with the specified value, depending on type: the number 5 is not the same as the string "5".
* false - Default value. Not depending on type, the number 5 is the same as the string "5". |
Return Values
Returns the keys, numeric and string, from the input array
Example
Try out following example:
<?php
$a=array("a"=>"Horse","b"=>"Cat","c"=>"Dog");
print_r(array_keys($a));
$a=array("a"=>"Horse","b"=>"Cat","c"=>"Dog");
print_r(array_keys($a,"Dog"));
$a=array(10,20,30,"10");
print_r(array_keys($a,"10",false));
?>
|
This will produce following result:
Array ( [0] => a [1] => b [2] => c )
Array ( [0] => c)
Array ( [0] => 0 [1] => 3 )
|
|
|
|