dsubq24666 2015-05-09 14:41
浏览 7
已采纳

PHP - 检查数组中的密钥存在

I have a file that contains a two denominational array:

<?php
return [
   'key1' => 'value1' ,
   'key2' => 'value2' ,
   'key3' => 'value3'
];
?>

I need to test for the presence of an array key. I am wondering what is the most efficient way of doing so? What is going to give me the fastest response time? At present this file is 1.2 megs. It is going to grow to the range of 10 megs.

Ron

  • 写回答

2条回答 默认 最新

  • doucan8049 2015-05-09 15:06
    关注

    Most efficient would be to use some better key-value store than array (SQLite, Redis, etc...). In all other ways you'll end up consuming memory, since array is initiated and memory is consumed in all cases.

    If you don't mind consuming memory and are trying to be efficient on CPU side and each array member has value, then probably...

    $array = include('myfile.php');
    if (isset($array[$mykey])) {
      echo "is set
    ";
    }
    

    ... is most efficient.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀