Home >Backend Development >PHP Tutorial >PHP interview question: These five coupons are 50, 40, 30, 20, 1. The order amount is X yuan. How many coupons can be returned using a method?
First of all, I excluded the order amount that was not an integer because the interviewer only gave me 7 minutes.
mou(99);//Call the following method here
function mou($x){
$array = array{50,40,30,20,1};
$temp = 0 ;
$j = $x ;
for($i=0;$ { $temp = $temp+foor($j/$array [$i]); $j = $j%$array[$i]; } echo "A total of ". $temp." coupons"; return $temp; } ?> This method is simply used to find a model. I hope some experts can give me a better method. Just reply directly
The above introduces the PHP interview questions: these five coupons are 50, 40, 30, 20, 1, the order amount is X yuan, how many coupons are returned using the method, including the content, I hope you are interested in the PHP tutorial Friends help.