-2

I have an Array like the following:

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 ) 
) 

How can I search the Array so that I can check the value of parentSlideID in each of the sub Array, and then return the keys where it finds a match.

For example, searching the array for "1" would return 0,1. Searching for "0" would return 2. Searching for "3" wouldn't return anything. Is this possible?

Chuck Le Butt
  • 47,570
  • 62
  • 203
  • 289
  • 1
    This has been asked several times before. For example, http://stackoverflow.com/questions/5835660/searching-within-all-keys-in-a-multidimensional-array-php – Jason McCreary May 22 '12 at 17:31
  • @Donut If you don't want to answer the question, don't! Questions are an opportunity to help someone and gain rep. If the question doesn't give you enough information to answer it, then ask for more. Otherwise what's the point in me listing what I've tried, when the answer is going to be very simple? – Chuck Le Butt May 22 '12 at 17:38
  • If answer is going to be simple, why won't you answwer yourself? – Robik May 22 '12 at 17:42
  • @Donut I think it's obvious that I did not mean "simple" to mean "easy", but "not complicated or involved". – Chuck Le Butt May 23 '12 at 09:22

2 Answers2

5

This should help:

foreach($array as $key=>$value)
{
    if($value['parentSlideID'] == $searchvalue)
        $results[]=$key;
}
Chuck Le Butt
  • 47,570
  • 62
  • 203
  • 289
Gareth
  • 5,693
  • 3
  • 28
  • 37
2

is this what you're looking for?

<?php
$needle = "1";
foreach($array as $key=>$value)
{
    if($value['parentSlideID']==$needle)
    {
       echo "$array[".$key."] is equal to: ".$needle;
       break;
    }
}
?>
Wampie Driessen
  • 1,654
  • 1
  • 13
  • 19