Blog

Chris
Harrison

Web Developer

My views on interesting things found on the Internet.

01.08.2011

dump() - Javascript equivalent of PHP's print_r()

This function in just came in very handy for debugging purposes. It's a javascript function that basically mimics print_r in PHP.

/**
 * Function : dump()
 * Arguments: The data - array,hash(associative array),object
 *    The level - OPTIONAL
 * Returns  : The textual representation of the array.
 * This function was inspired by the print_r function of PHP.
 * This will accept some data as the argument and return a
 * text that will be a more readable version of the
 * array/hash/object that is given.
 * Docs: http://www.openjs.com/scripts/others/dump_function_php_print_r.php
 */
function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

01.30.2011

20 Ways to Save Kittens and Learn PHP

A good read from net tuts for PHP developers, mostly common sense stuff but it doesn't hurt to brush up on best practices. I've been guilty of not giving my variables obvious names when rushing through a piece of code, so it helps to have these called out so they remain top of mind. And you can't help but love a list that goes from 0-19.