0

I have the following array:

Array
(
    [fall] => Array
        (
            [info] => Array
                (
                    [Name] => Test
                    [Description] => Test description
                    [Slug] => tester
                )

            [images] => Array
                (
                    [0] => fall_1.jpg
                    [1] => fall_2.jpg
                    [2] => fall_3.jpg
                    [3] => fall_4.jpg
                )

        )

    [spring] => Array
        (
            [images] => Array
                (
                    [0] => spring_1.jpg
                    [1] => spring_2.jpg
                    [2] => spring_3.jpg
                    [3] => spring_4.jpg
                    [4] => spring_5.jpg
                )

        )

)

What I'm looking to do is get the fall array if both info exists and Slug is equal to tester. I researched and saw this question/answer but mine is dependent on a sub-array being available -- would it be the same idea?

As an example, if tester was the only param given, I'd want the fall array to be returned.

3
  • 1
    I don't know what you mean by "I'd want to be able to return the array position that has the slug if the slug is the only param given" Commented Sep 2, 2013 at 23:04
  • If the slug tester was given, I'd want the fall array to be returned. Commented Sep 2, 2013 at 23:08
  • That's exactly what my answer does. Commented Sep 3, 2013 at 19:30

2 Answers 2

2

You could easily just do

if (isset($array['fall']['info']['Slug']) && $array['fall']['info']['Slug'] == 'tester') {
    return $array['fall'];
}
Sign up to request clarification or add additional context in comments.

2 Comments

Hi, appreciate the answer. To clarify, I'd want to be able to return the array position that has the slug if the slug is the only param given (going to be doing this from a $_GET param. Thanks.
You should edit your question to explain exactly what you want because it is unclear.
0

Same answer as the one you linked.

if(is_array($your_array_name['fall']['info']) && $your_array_name['fall']['info']['Slug'] == 'tester') {
  // Execute code here...
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.