如何检查另一个数组中是否存在该数组键?

时间:2017-01-18 11:01:54

标签: php arrays cakephp-2.0

我使用CakePHP 2.0框架,我遇到了一个问题。它给了我以下错误。我还使用了array_key_exists

: Undefined offset: 2 [APP/View/Doctors/admin_customize_plan_new.ctp, line 28]style="display:none"; id="checktab4">

我有两个数组。首先存储在$carePlansList

Array
(
[0] => Array
    (
        [EveCarePlansList] => Array
            (
                [id] => 1
                [care_plan_name] => CHF
            )

    )

[1] => Array
    (
        [EveCarePlansList] => Array
            (
                [id] => 3
                [care_plan_name] => Hypertension
            )

    )

[2] => Array
    (
        [EveCarePlansList] => Array
            (
                [id] => 4
                [care_plan_name] => ABC
            )

    )
)

第二个名为$QuestionUserexists

Array
(
[0] => Array
    (
        [EveChfQuestionsUser] => Array
            (
                [cq_cp_id] => 1
            )

    )

[1] => Array
    (
        [EveChfQuestionsUser] => Array
            (
                [cq_cp_id] => 3
            )

    )

)

现在当我在这两个数组之间进行比较时,我会得到上面的错误。

我的foreach循环是:

<?php 
foreach ($carePlansList as $key => $plansList) { ?>
    <li role="presentation" class="planLists" 
    <?php if($QuestionUserexists[$key]['EveChfQuestionsUser']['cq_cp_id'] == $plansList['EveCarePlansList']['id'] ){ 
        }else{?>
                style="display:none";
            <?php } ?>>
    </li>

1 个答案:

答案 0 :(得分:1)

添加支票:isset()

[* TO 0]