PHP Recursively walk array and link element...

interclubs
interclubs used Ask the Experts™
on
I have a large array (with a bunch of sub arrays) and I want to recursively go through it, and if the key ='id' I want to change the value to be:
<a href="?[this_value]">[this_value]</a>
where [this_value] is the value of the id key.

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
function replace_id(&$val, $key)
{
    if ($key == 'id')
      $val = "<a href=\"?$val\">$val</a>";
}
array_walk_recursive($large_array, 'replace_id');

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial