Costinu’s Blog

When you dream, there are no rules. People can fly; anything can happen. Sometimes, there’s a moment as you’re waking, and you become aware of the real world around you; but you’re still dreaming. You may think you can fly, but you better not try.
Oct 5
JavaScript:
  1. /**
  2. *function : print_r()
  3. *@param: array-array,hass or object
  4. *@param: level - OPTIONAL
  5. *@returns: string - The textual representation of the array.
  6. */
  7. function print_r(array,level) {
  8. var dumped_text = "";
  9. if(!level) level = 0;
  10. //The padding given at the beginning of the line.
  11. var level_padding = "   ";
  12. for(var j=0;j<level;j++) level_padding += "    ";
  13. if(typeof(array) == 'object') { //Array/Hashes/Objects
  14. var obj = 0;
  15. for(var item in array) {
  16. var value = array[item];
  17. if(typeof(value) == 'object') { //If it is an array,
  18. dumped_text += level_padding + "[" + item + "] => Array\n " + level_padding + "( \n";
  19. dumped_text += print_r(value,level+1);
  20. dumped_text += level_padding + ")\n";
  21. } else {
  22. dumped_text += level_padding + level_padding +  "[" + item + "] => " + value + "\n";
  23. }
  24. }
  25. } else { //Stings/Chars/Numbers etc.
  26. dumped_text = "===>"+array+"<===("+typeof(array)+")";
  27. }
  28. return dumped_text;
  29. }
  30. /**
  31. *call of function
  32. */
  33. alert (print_r (MyArray));

Bookmark and Share:

1 Comentariu »

  1. This shit is really useful.

    Comentariu de mihai — Octombrie 8, 2007 @ 10:56 am

Feed RSS pentru acest articol. TrackBack URI

Adaugă un comentariu


Comments links could be nofollow free.