In order to print_r a collapsable tree, I\'m currently using his code which uses preg_replace() and the /e modifier, which is depreciated
print_r
preg_replace()
/e
You need to concat the variable $id value, try this:
function callbackFunction($matches) { $id = substr(md5(rand().$matches[0]), 0, 7); return "$matches[1]<a href=\"javascript:toggleDisplay('$id');\">$matches[2]</a><div id='$id' style=\"display: none;\">'"; }