array_keys_PHP array_keys()函数与示例
array_keys
PHP array_keys()函數 (PHP array_keys() function)
array_keys() function is used to get the keys of an array, it accepts an array as an argument and returns a new array containing keys.
array_keys()函數用于獲取數組的鍵,它接受一個數組作為參數并返回一個包含鍵的新數組。
Syntax:
句法:
array_keys(input_array, [value], [strict]);Here,
這里,
input_array is an array (i.e. input array).
input_array是一個數組(即輸入數組)。
value is an optional parameter, it is used to define a value if the value is defined, then the only keys having that value are returned.
value是一個可選參數,如果定義了值,則用于定義值,然后僅返回具有該值的鍵。
strict is also an optional parameter, it is default set to false if we set it true the type of values will be checked.
嚴格也是一個可選的參數,它是默認設置為false,如果我們把它真值的類型將被檢查。
Examples:
例子:
Input:$per = array("name" => "Amit", "age" => 21, "gender" => "Male");Output:Array ([0] => name [1] => age [2] => gender )PHP code 1: array with and without containing keys
PHP代碼1:包含和不包含鍵的數組
<?php$per = array("name" => "Amit", "age" => 21, "gender" => "Male");print ("keys array...\n");print_r (array_keys($per));//array with out keys $arr = array("Hello", "world", 100, 200, -10);print ("keys array...\n");print_r (array_keys($arr)); ?>Output
輸出量
keys array... Array ([0] => name [1] => age [2] => gender ) keys array... Array ([0] => 0[1] => 1[2] => 2[3] => 3[4] => 4 )PHP code 2: Using value and strict mode
PHP代碼2:使用值和嚴格模式
<?php$arr = array("101" => 100, "102" => "100", "103" => 200);print("output (default function call)...\n");print_r (array_keys($arr)); print("output (with checking value)...\n");print_r (array_keys($arr, 100)); print("output (with checking value & strict mode)...\n");print_r (array_keys($arr, 100, true)); ?>Output
輸出量
output (default function call)... Array ( [0] => 101[1] => 102[2] => 103 ) output (with checking value)... Array ( [0] => 101[1] => 102 ) output (with checking value & strict mode)... Array ( [0] => 101 )翻譯自: https://www.includehelp.com/php/array_keys-function-with-example.aspx
array_keys
總結
以上是生活随笔為你收集整理的array_keys_PHP array_keys()函数与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 没有安装node对等点依赖_功能依赖项的
- 下一篇: java字符串转字符串列表_Java中的