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.

Community
  • 1
  • 1
Zach
  • 1,185
  • 3
  • 24
  • 60

2 Answers2

2

You could easily just do

if (isset($array['fall']['info']['Slug']) && $array['fall']['info']['Slug'] == 'tester') {
    return $array['fall'];
}
Mike
  • 23,542
  • 14
  • 76
  • 87
  • 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. – Zach Sep 02 '13 at 22:57
  • You should edit your question to explain exactly what you want because it is unclear. – Mike Sep 02 '13 at 23:00
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...
}
Shylo Hana
  • 1,792
  • 13
  • 10