[JS] php print_r-like


/ Published in: JavaScript
Save to your folder(s)

/*Coded by Alessio Delmonti - www.tecnocrazia.com */


Copy this code and paste it in your HTML
  1. function dump(arr,level) {
  2. var dumped_text = "";
  3. if(!level) level = 0;
  4.  
  5. var level_padding = "";
  6. for(var j=0;j<level+1;j++) level_padding += " ";
  7.  
  8. if(typeof(arr) == 'object') {
  9. for(var item in arr) {
  10. var value = arr[item];
  11.  
  12. if(typeof(value) == 'object') { //If it is an array,
  13. dumped_text += level_padding + "'" + item + "' ...\n";
  14. dumped_text += dump(value,level+1);
  15. } else {
  16. dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
  17. }
  18. }
  19. } else { //Stings/Chars/Numbers etc.
  20. dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
  21. }
  22. return dumped_text;
  23. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.