Hey guys

i jst wanna ask about how to put categories in php in such a that i write a function that will take a specific surname as a parameter and check in which category of letters it falls to and return the name of the person

e.g muller
category: M-o

7 Years
Discussion Span
Last Post by ddymacek
function get_category($name) {
	// get the first letter of the name passed in.
	$first_letter = substr($name,0,1);
	// normalize it, in this case lets make them all lowercase.
	$lowercase = strtolower($first_letter);
	// I was going to make an array of categories, but this will do the job...
	$category = '';
	if ($lowercase == 'a' || $lowercase == 'b' || lowercase == 'c') {
		$category = "A-C";
	} else if ($lowercase == 'd' || $lowercase == 'e' || lowercase == 'f') { 
		$category = "D-F";
	} else if ($lowercase == 'g' || $lowercase == 'h' || lowercase == 'i') { 
		$category = "G-I";
	// continue on with your else if statements until all of your categories are defined.
	} else {
		$category = "Undefined";
	return $category;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.