Here is some tips:
- Name of function should be clearer
- Try to avoid ctype_digit usage, because it may produce unexpected results - ctype_digit(42) returns FALSE
- Because you working with integers, you should cast values to integers, note that inputs are always strings.
- You must check for negative values, also.
- Second can be 0 for example: 2 min and 0 sec. Also, some songs can lasts lower then minute (Classic songs)
- Consider that some CD song may have duration more then 60 min, CD medium can store 80min and it can be one song, some mix or classic songs. So, maybe you should avoid minute check.
59) {
$warning['sec'] = 'The seconds must be between 0 and 59';
}
if($min 60) {
$warning['min'] = 'The minutes must be between 0 and 60';
}
// for songs bigger then 60 minutes
if($min == 60 && $sec > 0) {
$warning['duration'] = "Song must last more then one second and maximum 60 minutes.";
}
return !empty($warning) ? $min * 60 + $sec : NULL;
}