Random Strings and Comparing Arrays - A Rant

published on January 16th, 2008 · more from the blog →

Again people amaze me with just how thick they can be. Basically I want to create a random string 8 characters long, a bit of google bashing gives me functions that are like 20 - 100 lines long, why people? why? here is my fabtabulous (and far better than yours) script for achieving this.

function random_string($length=8){
	$charset = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','X','Z','0','1','2','3','4','5','6','7','8','9','0');
	$chars = array_rand($charset,$length);
	foreach ($chars as $a=>$value){
		$key.= $charset[$value];
	return $key;

See how easy it is people! Love you really

And while i'm ranting about stuff... comparing 2 multidimensional arrays, hello php? bah.. here's my very simple solution!

function array_compare($array1,$array2){
	return (md5(serialize($array1)) == md5(serialize($array2))) ? true : false;