Anyone ever hear of anything like this?
I would like to make a multi-dimensional array act like a collapsible tree, would this require me to do too much manual labor or is something already made?
Anyone ever hear of anything like this?
I would like to make a multi-dimensional array act like a collapsible tree, would this require me to do too much manual labor or is something already made?
Also found this little nugget on PHP.net, its dirty but works out the box
function print_r_tree($data)
{
// capture the output of print_r
$out = print_r($data, true);
// replace something like '[element] => <newline> (' with <a href="javascript:toggleDisplay('...');">...</a><div id="..." style="display: none;">
$out = preg_replace('/([ \ ]*)(\\[[^\\]]+\\][ \ ]*\\=\\>[ \ ]*[a-z0-9 \ _]+)\
[ \ ]*\\(/iUe',"'\\\\1<a href=\\"javascript:toggleDisplay(\\''.(\\$id = substr(md5(rand().'\\\\0'), 0, 7)).'\\');\\">\\\\2</a><div id=\\"'.\\$id.'\\" style=\\"display: none;\\">'", $out);
// replace ')' on its own on a new line (surrounded by whitespace is ok) with '</div>
$out = preg_replace('/^\\s*\\)\\s*$/m', '</div>', $out);
// print the javascript function toggleDisplay() and then the transformed output
echo '<script language="Javascript">function toggleDisplay(id) { document.getElementById(id).style.display = (document.getElementById(id).style.display == "block") ? "none" : "block"; }</script>'."\
<pre>$out</pre>";
}
Krumo is exactly what Im looking for ty
You’re welcome!
Krumo is pretty cool. I don’t use it in my CMS, but I’ve used it for other projects.
You should take a look at krumo, it does pretty much what you want.
It would be a fairly trivial exercise to parse the output/returned value from print_r to present it in whatever format you like (e.g differently for CLI and CGI).
Yeah, sounds like a job for jQuery, but it’d be nice if that could be built into tools such as xdebug. I cannot quite see how though.
Somebody almost certainly already made something like that
But a php function that does that, I don’t think so. You’ll have to search for such a script, or write one yourself.