PHP Recursive JSON Children Search
<p>I need to parse JSON which looks like this:</p>

<pre><code>{
    "mdfId":"282088127",
    "mdfConcept":"ME 3400EG-12CS-M Switch",
    "children":[
        {
            "mdfId":"007",
            "mdfConcept":"Another item",
            "children": [
                // many more here
            ]
        },
        {
             "mdfId":"008",
             "mdfConcept":"Another one",
             "children": [
                 {
                     "mdfId":"010",
                     "mdfConcept":"What I'm looking for!",
                     "children": [] // no children
                 }
             ]
        },
        // many more here
    ]
},
</code></pre>

<p>This is a recursive structure in which every element has <code>mdfId</code>, <code>mdfConcept</code> and <code>children</code> keys. </p>

<p>Say I need to find node with <code>ID=010</code> within this structure. I don't know at which level it lies (e.g. it can be on top level, or several <code>children</code> nodes below). </p>

<p>My current approach is:</p>

<pre><code>$mdfId = '010'; // what I'm loking for

foreach ($jsonResponse as $category) {
    while (true) {
        if ($category['mdfId'] == $mdfId) {
            // we found it!
            $categoryDevices[$mdfId] = $category['children'];
            break 2;
        }

        if (!empty($category['children'])) {
            next_cat:

            if (is_null($category['children'])) {
                break;
            }

            $category = array_shift($category['children']);
            continue;
        }

        if (empty($category['children'])) {
            goto next_cat;
        }
    }
}
</code></pre>

<p>But current approach misses some cases. How can I optimize this recursive loop so it checks all nodes on same level and each one accesible through any number of <code>children</code> keys?</p>