1function array_dump( $var ) { 2 3$resString=""; 4// The gettype function returns the data type 5 // of its parameter. 6switch (gettype($var)) { 7 8// inter, double, and strings are simply 9 // displayed. 10case'integer': 11case'double': 12case'string': 13$resString.="$var\n"; 14break; 15 16// array datatypes need to specially 17 // handled. 18case'array': 19$resString.="Array\n(\n"; 20// if the array has no entries, display 21 // a message. 22if (!Count($var)) { 23$resString.="\tEmpty Array.\n"; 24 } 25else { 26 27 28// use a do loop to iterate over the 29 // entries in the array. 30do { 31$resString.="\t[".key($var)."] => "; 32 33// perform the magic of recursion using the 34 // VALUE of the current key/value pair. 35$resString.= array_dump($var[key($var)]); 36 } while (next($var)); 37 38// end the HTML table after all of the 39 //array entries have been displayed. 40 } 41$resString.=")\n"; 42break; 43 44// switch statements should always have a default 45 // clause - just in case the data has a value 46 // your program doesn't expect. 47default: 48$resString.="unknown data type\n"; 49break; 50 } 51return$resString; 52}