如何检查另一个数组中是否存在数组键?
how to check that array key exists in another array?
我正在使用 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>
添加支票:isset()
foreach ($carePlansList as $key => $plansList) { ?>
<li role="presentation" class="planLists"
<?php if(isset($QuestionUserexists[$key]) &&
$QuestionUserexists[$key]['EveChfQuestionsUser']['cq_cp_id'] == $plansList['EveCarePlansList']['id'] ){
}else{?>
style="display:none";
<?php } ?>>
</li>
endforeach;
我正在使用 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>
添加支票:isset()
foreach ($carePlansList as $key => $plansList) { ?>
<li role="presentation" class="planLists"
<?php if(isset($QuestionUserexists[$key]) &&
$QuestionUserexists[$key]['EveChfQuestionsUser']['cq_cp_id'] == $plansList['EveCarePlansList']['id'] ){
}else{?>
style="display:none";
<?php } ?>>
</li>
endforeach;