title: Search filter in multidimensional array in php
body: <p>How would I create a search function that search in multidimensional nested array?</p>
  
  <p>Given the following array :</p>
  
  <pre><code>Array
  (
  [0] =&gt; Array
      (
          [id] =&gt; 1
          [parent_name] =&gt; ACTIVITIES
          [children] =&gt; Array
              (
              )
  
      )
  
  [1] =&gt; Array
      (
          [id] =&gt; 2
          [parent_name] =&gt; ANIMALS/PETS
          [children] =&gt; Array
              (
              )
  
      )
  
  [2] =&gt; Array
      (
          [id] =&gt; 3
          [parent_name] =&gt; ART
          [children] =&gt; Array
              (
                  [0] =&gt; Array
                      (
                          [post_id] =&gt; 100
                          [child_name] =&gt; Bookeeping
                          [painting] =&gt; Array
                              (
                                  [0] =&gt; flower
                                  [1] =&gt; beach
                                  [2] =&gt; sunrise
                              )
  
                      )
  
                  [1] =&gt; Array
                      (
                          [post_id] =&gt; 101
                          [child_name] =&gt; Addiction
                          [painting] =&gt; Array
                              (
                                  [0] =&gt; sunrise
                                  [1] =&gt; beach
                              )
  
                      )
  
              )
  
      )
  [3] =&gt; Array
      (
          [id] =&gt; 4
          [parent_name] =&gt; Music
          [children] =&gt; Array
              (
                  [0] =&gt; Array
                      (
                          [post_id] =&gt; 102
                          [child_name] =&gt; POP
                          [painting] =&gt; Array
                              (
                                  [0] =&gt; suntown
                                  [1] =&gt; beachfull
                                  [2] =&gt; sunrise
                              )
  
                      )
  
                  [1] =&gt; Array
                      (
                          [post_id] =&gt; 103
                          [child_name] =&gt; Rock
                          [painting] =&gt; Array
                              (
                                  [0] =&gt; sunrisenew
                                  [1] =&gt; beachnew
                              )
  
                      )
  
              )
  
      )
  )
  </code></pre>
  
  <p>How would I filter this array with a key which search in 'painting'?</p>
  
  <p>For example search key is "sun"</p>
  
  <p>Result should be like this :</p>
  
  <pre><code>Array
  (
  
  [2] =&gt; Array
      (
          [id] =&gt; 3
          [parent_name] =&gt; ART
          [children] =&gt; Array
              (
                  [0] =&gt; Array
                      (
                          [post_id] =&gt; 100
                          [child_name] =&gt; Bookeeping
                          [painting] =&gt; Array
                              (
                                  [2] =&gt; sunrise
                              )
  
                      )
  
                  [1] =&gt; Array
                      (
                          [post_id] =&gt; 101
                          [child_name] =&gt; Addiction
                          [painting] =&gt; Array
                              (
                                  [0] =&gt; sunrise
                              )
  
                      )
  
              )
  
      )
  [3] =&gt; Array
      (
          [id] =&gt; 4
          [parent_name] =&gt; Music
          [children] =&gt; Array
              (
                  [0] =&gt; Array
                      (
                          [post_id] =&gt; 102
                          [child_name] =&gt; POP
                          [painting] =&gt; Array
                              (
                                  [0] =&gt; suntown
                              )
  
                      )
  
                  [1] =&gt; Array
                      (
                          [post_id] =&gt; 103
                          [child_name] =&gt; Rock
                          [painting] =&gt; Array
                              (
                                  [0] =&gt; sunrisenew
                              )
  
                      )
  
              )
  
      )
  )
  </code></pre>