Posted By

Mosaic on 11/18/10


Tagged

array


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

letanure


[JS] php print_r-like


 / Published in: JavaScript
 

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

  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  

You need to login to post a comment.