shamuraq Posted August 18, 2009 Share Posted August 18, 2009 Hi there, I'm trying to do a function to get the values of $hour_1,$min_1,$hour_name and $min_name. Can anyone help me see what went wrong? <? php function min2hrmin($hour_1,$min_1,$hour_name,$min_name){ $min = rand(60,999); //echo $min.'<br>'; $hour = $min / 60; $hour_1 = floor($min / 60); //Sorting Singular and plural form if($hour_1 < 1){ $hour_name = 'hour'; } else{ $hour_name = 'hours'; } $min_1 = $min % 60; //Sorting Singular and plural form if($min_1 < 1){ $min_name = 'minute'; } else{ $min_name = 'minutes'; } return ($hour_1,$min_1,$hour_name,$min_name); } echo $hour.'<br>'; echo $min.'<br>'; echo $hour_1.'<br>'; echo $min_1.'<br>'; echo $hour_name.'<br>'; echo $min_name.'<br>'; ?> Link to comment https://forums.phpfreaks.com/topic/170872-solved-function-help-anyone/ Share on other sites More sharing options...
wildteen88 Posted August 18, 2009 Share Posted August 18, 2009 Well nothing will happen if you don't call your function first. However return does not return variables, it returns the value of a variable. Link to comment https://forums.phpfreaks.com/topic/170872-solved-function-help-anyone/#findComment-901205 Share on other sites More sharing options...
ignace Posted August 18, 2009 Share Posted August 18, 2009 However return does not return variables, it returns the value of a variable. Unless you wrap it inside an array: return array($hour_1,$min_1,$hour_name,$min_name); acess using: list($hour_1, $min_1, $hour_name, $min_name) = min2hrmin(..);//assuming you want to overwrite $hour_1, .. use different variable names otherwise Don't calculate $hour twice: $hour = $min / 60; $hour_1 = floor($hour/*not $min / 60*/); if($hour_1 < 1) Always returns false as $min >= 60 && $min <= 999, thus $hour_1 is always >= 1 Link to comment https://forums.phpfreaks.com/topic/170872-solved-function-help-anyone/#findComment-901210 Share on other sites More sharing options...
shamuraq Posted August 18, 2009 Author Share Posted August 18, 2009 Whoa you guys are pros talking man... so is the function format wrong or the structure in the if() is wrong? Lol.. Sorry guys. Bit slow here...I can't get the function to work. Its blank screen Link to comment https://forums.phpfreaks.com/topic/170872-solved-function-help-anyone/#findComment-901218 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.