I have six strings that go through the process of transforming into an array, sorting by case insensitive natural order, trimmed, converted to lower case, looped, printed out with each first-letter capitalized and a XHTML break added.
The problem is that I have to do it six different times; it becomes redundant. I've tried throwing the strings into a multidimensional array, but couldn't get it right. I'd like to stay away from creating functions, if at all possible, because of the extra memory requirements.
<?php
/////////////////////////////////////////////////
// These six strings are normally included //
// through an external file, and are included //
// here for reference. //
/////////////////////////////////////////////////
$dex_skills = "blaster, dodge, melee combat, melee parry, missile weapons, pick pocket";
$per_skills = "bargain, con, hide,search, sneak";
$kno_skills = "languages, streetwise, survival";
$str_skills = "climbing/jumping, stamina, swimming";
$mec_skills = "beast riding, ground vehicle operation, repulsorlift operation";
$tec_skills = "droid programming, droid repair, first aid, repulsorlift repair";
/////////////////////////////////////////////////
// The following blocks of code are identical //
// with the exception of the variables they //
// process. //
/////////////////////////////////////////////////
################################################
// DEXTERITY SKILLS
$dex_array = explode(",", $dex_skills);
natcasesort($dex_array);
foreach ($dex_array as $dex_value) {
$dex_value = trim(strtolower($dex_value));
// PRINT SKILLS
print ucwords(nl2br("$dex_value\n"));
}
#################################################
// PERCEPTION SKILLS
$per_array = explode(",", $per_skills);
natcasesort($per_array);
foreach ($per_array as $per_value) {
$per_value = trim(strtolower($per_value));
// PRINT SKILLS
print ucwords(nl2br("$per_value\n"));
}
#################################################
// KNOWLEDGE SKILLS
$kno_array = explode(",", $kno_skills);
natcasesort($kno_array);
foreach ($kno_array as $kno_value) {
$kno_value = trim(strtolower($kno_value));
// PRINT SKILLS
print ucwords(nl2br("$kno_value\n"));
}
#################################################
// STRENGTH SKILLS
$str_array = explode(",", $str_skills);
natcasesort($str_array);
foreach ($str_array as $str_value) {
$str_value = trim(strtolower($str_value));
// PRINT SKILLS
print ucwords(nl2br("$str_value\n"));
}
#################################################
// MECHANICAL SKILLS
$mec_array = explode(",", $mec_skills);
natcasesort($mec_array);
foreach ($mec_array as $mec_value) {
$mec_value = trim(strtolower($mec_value));
// PRINT SKILLS
print ucwords(nl2br("$mec_value\n"));
}
#################################################
// TECHNICAL SKILLS
$tec_array = explode(",", $tec_skills);
natcasesort($tec_array);
foreach ($tec_array as $tec_value) {
$tec_value = trim(strtolower($tec_value));
// PRINT SKILLS
print ucwords(nl2br("$tec_value\n"));
}
#################################################
?>
Any ideas would be helpful 😃