【发布时间】:2016-05-10 21:32:54
【问题描述】:
我有这个数组:
$list_desings_ids = array('hc1wXBL7zCsdfMu','dhdsfHddfD','otheridshere');
用 die() + var_dumo() 这个数组返回我:
array:2 [▼
0 => "hc1wXBL7zCsdfMu"
1 => "dhdsfHddfD"
2 => "otheridshere"
]
我想检查 $list_desings_ids 数组中是否存在 design_id。
例如:
foreach($general_list_designs as $key_design=>$design) {
#$desing->desing_id return me for example: hc1wXBL7zCsdfMu
if(array_key_exists($design->design_id, $list_desings_ids))
$final_designs[] = $design;
}
但这对我不起作用,正确的方法是什么?
【问题讨论】:
-
使用 in_array() 函数而不是 array_key_exists ...因为您的 $list_designs_ids 数组未根据您的描述声明为键和值对。