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?

share|improve this question

2  
What Have You Tried? – Robik May 22 at 17:31
1  
This has been asked several times before. For example, stackoverflow.com/questions/5835660/… – Jason McCreary May 22 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? – Django Reinhardt May 22 at 17:38
If answer is going to be simple, why won't you answwer yourself? – Robik May 22 at 17:42
@Donut I think it's obvious that I did not mean "simple" to mean "easy", but "not complicated or involved". – Django Reinhardt May 23 at 9:22
feedback

2 Answers

up vote 5 down vote accepted

This should help:

foreach($array as $key=>$value)
{
    if($value['parentSlideID'] == $searchvalue)
        $results[]=$key;
}
share|improve this answer
feedback

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;
    }
}
?>
share|improve this answer
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.