title: Recursive call in php over a json
body: <p>I have this json data</p>
  
  <pre><code>$innerdata = json_decode('{
              "sync_block": false,
              "contacts": [{
                  "con_title": "",
                  "con_fName": "",
                  "con_lName": "",
                  "con_job_title": "",
                  "emails": [{
                      "email": "",
                      "type": "",
                      "primary": false,
                      "nest_uid": "1_1_1536657342_lyBhkbkDfG",
                      "checked": false
                  },
                  {
                      "email": "",
                      "type": "",
                      "primary": false,
                      "nest_uid": "1_1_1536657342_lyBhkbkDfGLp",
                      "checked": false
                  }],
                  "phones": [{
                      "phone": "",
                      "type": "",
                      "primary": false,
                      "nest_uid": "1_1_1536657342_CQPBBUBRZN",
                      "checked": false
                  }],
                  "nest_uid": "1_1_1536657342_fpTI2RF3XK",
                  "checked": false
              }]
          }');
  </code></pre>
  
  <p>Then I get the nest_uid that I need to find </p>
  
  <pre><code>$uid='1_1_1536657342_lyBhkbkDfGLp';
  </code></pre>
  
  <p>I need to do recursive call over the json and return the object whose </p>
  
  <pre><code>nest_uid == $uid
  </code></pre>
  
  <p>In the above json the output should be </p>
  
  <pre><code>{
                      "email": "",
                      "type": "",
                      "primary": false,
                      "nest_uid": "1_1_1536657342_lyBhkbkDfGLp",
                      "checked": false
                  }
  </code></pre>
  
  <p>I tried writing a function but it doesn't work as expected</p>
  
  <pre><code>function  traverse($innerdata,$uid){
          $res=$innerdata;
          foreach($innerdata as $key=&gt;$property)
          {
              if($key=='nest_uid'&amp;&amp; $property ==$uid)
              {
                  break;
  
              }
              else if(is_array($property))
              {
                   foreach($property as $innerproperty){
                       echo "1";
                     traverse($innerproperty,$uid);     
                   }
  
              }
          }
  
         return $res;  
  
    }
  </code></pre>
  
  <p>if someone could help me would be great</p>