- Trang chủ
- Phát triển web
- PHP
- Hàm array_keys[] trong PHP
Hướng dẫn cách sử dụng hàm array_keys[] về mảng trong lập trình PHP
Tác dụng của hàm array_keys[]
The array_keys[] function return all the keys or a subset of the keys of an array.
The following table summarizes the technical details of this function.
Returns an array containing the keys. |
PHP 4+ |
Syntax
The basic syntax of the array_keys[] function is given with:
array_keys[array, value, strict];
The following example shows the array_keys[] function in action.
Parameters
The array_keys[] function accepts the following parameters.
array | Required. Specifies the array to be used. |
value | Optional. If specified, then only keys containing these values are returned. |
strict | Optional. Determines if strict comparison [===] should be used during the value search. Possible values are true and false. Default value is false. |
Note: In strict comparison [using strict equality === operator] value and data type must be equal, therefore in strict comparison integer 4 is not equal to string "4".
More Examples
Here're some more examples showing how array_keys[] function actually works:
The following example return all the keys from the persons array containing the value 32.
The following example will return only those key which has integer value 32 using strict comparison. This can be simply done by setting the strict parameter to true.