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 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 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."); 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 ;/ 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
Archived
This topic is now archived and is closed to further replies.