我有这个数组:
$list_desings_ids = array('hc1wXBL7zCsdfMu','dhdsfHddfD','otheridshere');
用 die() + var_dump() 这个数组返回我:
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
。
尝试
$design_id = 'hc1wXBL7zCsdfMu';
$list_desings_ids = array('hc1wXBL7zCsdfMu','dhdsfHddfD','otheridshere');
if(in_array($design_id, $list_desings_ids))
{
echo "Yes, design_id: $design_id exits in array";
}
关于php - 检查数组中是否存在一个值(Laravel 或 Php),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35147366/