Hướng dẫn dùng has 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.
SyntaxThe 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. 18, "Clark"=>"32", "John"=>24, "Peter"=>32); // Getting all the keys from the persons array print_r(array_keys($persons)); ?> ParametersThe array_keys() function accepts the following parameters.
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 ExamplesHere'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. 18, "Clark"=>"32", "John"=>24, "Peter"=>32); // Getting all the keys having value 32 print_r(array_keys($persons, 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. 18, "Clark"=>"32", "John"=>24, "Peter"=>32); // Getting all the keys having integer value 32 print_r(array_keys($persons, 32, true)); ?> Bài viết này đã giúp ích cho bạn?Bài viết mới |