slpctrl Posted September 23, 2009 Share Posted September 23, 2009 First off, here's the script: <?php $num = array(); For ($i = 1000; $i > 0; $i--){ if !($num/3) && || !($num/5) { $i--; } else{ array_push($num, $i); echo "$i\n"; $i--; } } echo array_sum($num); ?> Now, what I'm trying to do is store every number under 1000 divisible by 3 or 5 into an array, and then add all the values in the array together; however, it doesn't work and I can't pinpoint where the error is. Any help is appreciated. Edit: Also, I have the echo "$i\n"; in there to help with finding the error; it echoes nothing :\. Link to comment https://forums.phpfreaks.com/topic/175244-mathdivision-script-wont-work/ Share on other sites More sharing options...
Mark Baker Posted September 23, 2009 Share Posted September 23, 2009 if ((($num % 3) != 0) || (($num % 5) != 0)) Link to comment https://forums.phpfreaks.com/topic/175244-mathdivision-script-wont-work/#findComment-923622 Share on other sites More sharing options...
slpctrl Posted September 23, 2009 Author Share Posted September 23, 2009 if ((($num % 3) != 0) || (($num % 5) != 0)) Doesn't work; I've got it down to this: <?php $num = array(); For ($i = 1000; $i > 0; $i--){ if ((($num % 3) != 0) || (($num % 5) != 0)) { array_push($num, $i); } echo array_sum($num); ?> I would think that'd work; but it doesn't. I've tried it with % and with /, nothing. When I insert that line just in my code, and move the code around so that it works it just echoes 1000 twice. :\ Link to comment https://forums.phpfreaks.com/topic/175244-mathdivision-script-wont-work/#findComment-923630 Share on other sites More sharing options...
knsito Posted September 23, 2009 Share Posted September 23, 2009 Didnt check the logic but you probably want if ((($i % 3) != 0) || (($i % 5) != 0)) Link to comment https://forums.phpfreaks.com/topic/175244-mathdivision-script-wont-work/#findComment-923671 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.