多使用isset,少使用in_array

输入:

$input = [

    "john" => 65,

    "tom" =>70,

            "jack" =>90,

]

判断姓名$name = "jack"是否在$input中:

刚接触php时很容易使用:in_array($name, $input) ,此时时间复杂度为O(n)

优化:isset($input[$name])  如果返回值非空且不为null,则说明$name存在于$input,时间复杂度为O(1)

原文地址:https://www.cnblogs.com/cing123/p/9832314.html