我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

如何检查PHP中哈希表中是否存在密钥?

At the moment I initialize as follows:

$my_hash = array();

Populate like this:

$my_hash[$key] = $value;

However when I check for my key as follows

if ($my_hash[$key])

The server throws up an error. How to I check for my key?

if(array_key_exists($key, $my_hash)){
    // do your stuff
}

It's not exactly a hash table. It's an array data type in PHP.

More operations on arrays can be seen here: http://php.net/manual/en/ref.array.php

http://www.php.net/manual/en/function.array-key-exists.php

if(array_key_exists($key, $hashtable)){
    // item is in the hastable
}

近期文章

  • PHP AMQP消费者在一段时间后没有回应
  • strtotime()的bug
  • 使用PDO进行行计数
  • 如何在输出窗口中运行Netbeans?
  • 使用Opencart从PHP字符串中删除字符
  • PHP在电子邮件中附加音频文件
  • Laravel网站循环导航订单
  • 将Socket.io与PHP Web应用程序和Nginx集成
  • Laravel 4中的行级ACL
  • 在安装Bitexchange脚本时在浏览器中获取PHP代码
  • 无法将工作作为ajax发布到php
  • Laravel phpunit用户拒绝访问
  • mysql FIND_IN_SET不使用带有整数值的php变量
  • 用jquery和ajax根据州改变城市
  • 从UTC转换时区
  • Laravel 5路由管理站点错误
  • 角度和php中的ajax请求
  • Javascript未在prestashop的产品页面上完全应用
  • 挂断Twilio时提交POST数据
  • Wordpress:使用页面作为“块”来调用模板

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华