我知道如何检查数组中的值,但如何在Array Iterator中检查值?
$array = new ArrayIterator(array(
'1QmRjtsw2UQ' => array('pubdate' => '26 Jun 15', 'alt' => '8 Year Old Beautifully Covers Thinking Out Loud', 'anchor text' => '8-yo \'Thinking Out Loud\''),
'eKqLaYrcf3A' => array('pubdate' => '25 Jun 15', 'alt' => 'Plane Lands On Truck', 'anchor text' => 'Plane Lands On Truck'),
));
我正在尝试检查1QmRjtsw2UQ
。
这不起作用:
if(in_array('1QmRjtsw2UQ', $array));
答案 0 :(得分:5)
为什么不使用array_key_exists?
if(array_key_exists('1QmRjtsw2UQ', $array))
{
// do something
}
答案 1 :(得分:0)
试试这个,
$array->offsetExists('1QmRjtsw2UQ');