8

我知道如何检查数组中的值,但是如何检查数组迭代器中的值?

$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));
4

2 回答 2

5

你为什么不使用array_key_exists

if(array_key_exists('1QmRjtsw2UQ', $array)) 
{
  // do something
}
于 2015-07-06T05:30:54.143 回答
0

尝试这个,

$array->offsetExists('1QmRjtsw2UQ');
于 2015-07-06T05:19:30.330 回答