key_exists()_PHP array_key_exists()函数与示例

key_exists()

PHP array_key_exists()函数 (PHP array_key_exists() function)

array_key_exists() function is used to check whether an array contains the given key or not. If key exists in the array – it returns true, if the key does not exist in the array – it returns false.

array_key_exists()函数用于检查数组是否包含给定键。 如果key存在于数组中-返回true ,如果key不存在于数组中-返回false 。

Syntax:

句法:

    array_key_exists(key, array);

Here,

这里,

  • key is the value of the key to be checked.

    key是要检查的密钥的值。

  • array is an input array, in which key will be checked.

    array是一个输入数组,将在其中检查键 。

Examples:

例子:

    Input:
    $arr = array("name" => "Amit", "age" => 21, "city" => "Gwalior");
   
    Output:
    array_key_exists("age", $arr): true
    array_key_exists("gender", $arr): false

PHP code:

PHP代码:

<?php
    $arr = array("name" => "Amit", "age" => 21, "city" => "Gwalior");
    
    //checking a key "age"
    if(array_key_exists("age", $arr)){
        print("array contains the key \"age\"\n");
    }
    else{
        print("array does not contain the key \"age\"\n");
    }

    //checking a key "gender"
    if(array_key_exists("gender", $arr)){
        print("array contains the key \"gender\"\n");
    }
    else{
        print("array does not contain the key \"gender\"\n");
    }        
?>

Output

输出量

array contains the key "age"
array does not contain the key "gender"


翻译自: https://www.includehelp.com/php/array_key_exists-function-with-example.aspx

key_exists()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值