I've got a simple function to conditionally convert units into feet or inches for display. I'd also like to use it to conditionally add the actual text ft or in to the end. I can't just add that text in every case, because I'd end up with 36 in x 24 in x 10 in when what you want is 36x24x10 in.
So basically I'm trying to do this:
function ex($x, $y) {
if only $x is specified {
if ($x < 50) {
return $x/25.4
}
else {
return $x/304.8
}
}
elseif $x and $y are both specified {
if ($x < 50) {
return ' in';
}
else {
return ' ft';
}
}
}
echo ex($NumberToConvert).'x'.ex($OtherNumberToConvert).example($NumberIWantToConvert,1);
But of course that results in "missing argument 2" warnings. The obvious hack is to use if ($y > 0) and always have to specify two arguments (making the latter 0 when I'm looking for numerical output and 1 when I'm looking for text). But is there something more elegant?
(yes I know this only makes sense if both numbers are <50 or neither are)
function ex($x, $y='') {