php - Value is still not setting to an integer? -
I have a simple script that will dynamically convert minutes, minutes, hours and days dynamically (it means That I have 1 minute, the script will keep "1 minute," and if I have 61 minutes, then the script will say "1 hour and 1 minute" etc. with proper grammar). Basically, although I try to set the value of a value as a variable, my current time (112 minutes) comes from: 1.8666666666667 hours and 52 minutes.
settype ($ otime, "integer"); Set type ($ hour, "integer"); Set type ($ min, "integer"); Set type ($ hour, "integer"); If ($ otime == 1) {$ otime = "1 minute"; } And if ($ otime & lt; 60 & $ otime! = 1) {$ otime = $ otime} "Minute"; } And if ($ otime> = 60 & $ otime <1440) {$ hours = $ otime / 60; $ Mins = $ otime% 60; If ($ min == 1 & amp; $ hours! = 1) {$ otime = $ hours "Hours and". $ Min "" minute ";} And if ($ min! = 1 & amp; $ hour == 1) {$ otime = $ hour." Hours and ". $ Min." Minutes ";} And if ($ min == 1 & amp; $ hour == 1) {$ otime = $ hours. "Hours and". $ Minutes. "Minutes";} and {$ otime = $ hours. "Hours and". $ Minutes. "Minutes ";}} And if ($ otime> = 1440) {$ days = $ otime / 1440; $ hours = $ otime% 1440; $ hours = $ hours / 60; $ mins = $ hour% 60; if ( $ Day == 1 more & amp; $ hours! = 1 & amp; $ minutes! = 1) {$ otime = $ day. "Days". $ Hours. "Hours and". $ Minutes. "Minutes";} If ($ day! = 1 & amp; $ hour == 1 & amp; amp; $ mins! = 1) {$ otime = $ day. "Days". $ Hour. "Hours and". $ Minutes. "Minutes ";} Aug R ($ day! = 1 & amp; $ hour! = 1 & amp; $ mins == 1) {$ otime = $ day. "Day". $ Hours. "Hours and". Mins. "Minutes ";} If ($ day == 1 and & amp; hour == 1 & amp; amp; $ mins! = 1) {$ otime = $ day." Day ". $ Hours." Hours and "$. Minute "minute";} if ($ day == 1 and & amp; hour = $ 1 = amp; $ mins == 1) {$ otime = $ day. "Day". $ Hour. "Hours And ". $ Min." Minutes ";} if ($ day! = 1 & amp; $ Hour == 1 & amp; Amp; $ Mins == 1) {$ otime = $ day "day". $ Hour "Hours and". $ Min " Minute "; } If ($ day == 1 more & amp; $ hours! = 1 & amp; amp; amp; amp; $ mins == 1) {$ otime = $ day "day". $ Hour "Hours and". $ Mins " Minute "; } If ($ day! = 1 & amp; $ hour! = 1 & amp; $ min! = 1) {$ otime = $ day "day". $ Hour "Hours and". $ Min " Minute "; }}
Besides - is there an easy way to do this? And if I miss any (for grammar purposes)
A lot easier to do without The way there are so many statements, but also provide the right multilingual language.
two minutes echo (1211); Working minutes 2 weeks ($ min) {$ m = floor ($ min% 60); $ H = Floor (($ min% 1440) / 60); $ D = floor ($ min / 1440); $ M_word = ($ m == 1? 'Min': 'min'); $ H_word = ($ h == 1? Hour ':' hours'); $ D_word = ($ d == 1? 'Day': 'days'); Return "$ d $ d_word $ h $ h_word and $ m $ m_word"; }
We reduce many of our details if the statements are 1 minute, 1 hour time, and if day 1, then just add them all to a string. Contrary to checking every possible case (if minutes 1 and hour are not 1 and not 1 day, if minutes are 1 hour, do not 1 day) 1) etc ...
Comments
Post a Comment