title: Searching in multidimensional php objects
body: <pre><code>    public function filter($index, $value) {
          if($this-&gt;tasks) {
              foreach ($this-&gt;tasks as $id =&gt; $t) {
                  if($t-&gt;$index != $value) {
                      unset($this-&gt;tasks[$id]);
                  }
              }
          } else {
              echo "Tasks are empty";
          }
      }
  </code></pre>
  
  <p>So I am having a problem with the function above searching multidimensional objects.  What I mean by that is like these:</p>
  
  <pre><code>$task-&gt;form-&gt;id
  $task-&gt;form-&gt;type
  $task-&gt;author-&gt;id
  $task-&gt;fields-&gt;[FIELDNAME]-&gt;value
  $task-&gt;form-&gt;template-&gt;id
  $task-&gt;id
  </code></pre>
  
  <p>etc.  These are the kinds of fields that need to be accessed.  I thought that I could just, in $index, put "form->id" but that didn't work.  For my application, I literally can spell it out.  I just don't want to have to write a function for each to the last, because some of them (as you can see) only need to be on the first level and some need to be all the way down four objects.</p>
  
  <p>Just tell me what more data you need and I will give it.  I know every keystroke intimately so it sometimes means I forget to share something.</p>
  
  <p>If you help, thank you so much.</p>
  
  <p><strong>WHAT I DID</strong></p>
  
  <hr>
  
  <p>Okay so I got it to work but I did something different. </p>
  
  <p>Within the <code>Form</code> class</p>
  
  <pre><code>public function search($value, $type = NULL) {
      if(is_object($this-&gt;fields)) {
          foreach($this-&gt;fields as $page) {
              foreach($page as $name=&gt;$field) {
                  if($name != "pdata") {
                      if ($type != NULL &amp;&amp; $field-&gt;type == $type &amp;&amp; $field-&gt;value == $value || $type == NULL &amp;&amp; isset($field-&gt;value) &amp;&amp; $field-&gt;value == $value) {
                          return true;
                      }
                  } 
              }
              return false;
          }
      } else {
          //Probably corrupted
          return false;
      }
      return false;
  }
  </code></pre>
  
  <p>Outside of it I can just call this function and delete or add based on whether it returns true or false. </p>