Canman2005 Posted April 2, 2009 Share Posted April 2, 2009 Hi all I have a form where I post a number value, such as $_POST['number'] = '230'; Is it possible to do a IF statement to say if the outputted number is in multiples of 5? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/152285-checking-for-in-multiples-of-5/ Share on other sites More sharing options...
kenrbnsn Posted April 2, 2009 Share Posted April 2, 2009 Use the mod operator "%" <?php if ($_POST['number'] % 5 === 0) echo $_POST['number'] . ' is divisible by 5'; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/152285-checking-for-in-multiples-of-5/#findComment-799728 Share on other sites More sharing options...
tibberous Posted April 2, 2009 Share Posted April 2, 2009 echo ($_POST['number'] % 5 ? '' : "{$_POST['number']} is divisible by 5."); Quote Link to comment https://forums.phpfreaks.com/topic/152285-checking-for-in-multiples-of-5/#findComment-799806 Share on other sites More sharing options...
Maq Posted April 2, 2009 Share Posted April 2, 2009 EDIT: I was wrong ;/ Quote Link to comment https://forums.phpfreaks.com/topic/152285-checking-for-in-multiples-of-5/#findComment-799814 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.