-2

我有一个如下所示的数组:

Array ( 
[0] => Array ( 
[slideID] => 3 
[parentSlideID] => 1 
[subSlideOrder] => 1 
[headline] => 
[copy] => 
[colourID] => 0 
[URL] => 2.jpg 
[category] => 1 
[visible] => 1 
[slideOrder] => 2 
[type] => 0 ) 

[1] => Array ( 
[slideID] => 3 
[parentSlideID] => 1 
[subSlideOrder] => 1 
[headline] => 
[copy] => 
[colourID] => 0 
[URL] => 2.jpg 
[category] => 1 
[visible] => 1 
[slideOrder] => 2 
[type] => 0 ) 

[2] => Array ( 
[slideID] => 3 
[parentSlideID] => 0 
[subSlideOrder] => 1 
[headline] => 
[copy] => 
[colourID] => 0 
[URL] => 2.jpg 
[category] => 1 
[visible] => 1 
[slideOrder] => 2 
[type] => 0 ) 
) 

如何搜索数组,以便检查parentSlideID每个子数组中的值,然后返回找到匹配项的键。

例如,在数组中搜索“1”将返回0,1. 搜索“0”将返回2。搜索“3”不会返回任何内容。这可能吗?

4

2 回答 2

5

这应该有助于:

foreach($array as $key=>$value)
{
    if($value['parentSlideID'] == $searchvalue)
        $results[]=$key;
}
于 2012-05-22T17:32:41.650 回答
2

这是你要找的吗?

<?php
$needle = "1";
foreach($array as $key=>$value)
{
    if($value['parentSlideID']==$needle)
    {
       echo "$array[".$key."] is equal to: ".$needle;
       break;
    }
}
?>
于 2012-05-22T17:33:01.887 回答