Created
November 23, 2022 09:54
-
-
Save damiencarbery/2f5d21d29710ee9cc34b3307a8576df5 to your computer and use it in GitHub Desktop.
Check whether numbers are divisible by 6 and are at least 6 (for checking the weight of a WooCommerce cart).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$weights = array( -6, 0, 2, 4, 6, 8, 10, 12, 13, 17, 18, 21, 24, 29, 30, 31 ); | |
$min_weight = 6; | |
$increments = 6; | |
foreach ( $weights as $weight ) { | |
echo "Weight: $weight\n"; | |
// Check if divisible by $increments. | |
if ( $weight % $increments == 0 ) { | |
echo "\tMultiple of $increments: Yes\n"; | |
// Verify it is at least $min_weight. | |
if ( $weight / $min_weight > 0 ) { | |
echo "\tAbove min weight: Yes\n"; | |
} | |
} | |
else { | |
echo "\tMultiple of $increments: No\n"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Weight: -6 | |
Multiple of 6: Yes | |
Weight: 0 | |
Multiple of 6: Yes | |
Weight: 2 | |
Multiple of 6: No | |
Weight: 4 | |
Multiple of 6: No | |
Weight: 6 | |
Multiple of 6: Yes | |
Above min weight: Yes | |
Weight: 8 | |
Multiple of 6: No | |
Weight: 10 | |
Multiple of 6: No | |
Weight: 12 | |
Multiple of 6: Yes | |
Above min weight: Yes | |
Weight: 13 | |
Multiple of 6: No | |
Weight: 17 | |
Multiple of 6: No | |
Weight: 18 | |
Multiple of 6: Yes | |
Above min weight: Yes | |
Weight: 21 | |
Multiple of 6: No | |
Weight: 24 | |
Multiple of 6: Yes | |
Above min weight: Yes | |
Weight: 29 | |
Multiple of 6: No | |
Weight: 30 | |
Multiple of 6: Yes | |
Above min weight: Yes | |
Weight: 31 | |
Multiple of 6: No |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment