if ($number % 6 != 0) {
$number += 6 - ($number % 6);
}
The modulus operator gives the remainder of the division, so $number % 6 is the amount left over when dividing by 6. This will be faster than doing a loop and continually rechecking.
If decreasing is acceptable then this is even faster:
$number -= $number % 6;
Related Contents:
- Show a number to two decimal places
- Are arrays in PHP copied as value or as reference to new variables, and when passed to functions?
- Visual Studio Code PHP Intelephense Keep Showing Not Necessary Error
- What’s the difference between echo, print, and print_r in PHP?
- How does the keyword “use” work in PHP and can I import classes with it?
- Getting a timestamp for today at midnight?
- Sanitizing strings to make them URL and filename safe?
- What does it mean to start a PHP function with an ampersand?
- file_get_contents(“php://input”) or $HTTP_RAW_POST_DATA, which one is better to get the body of JSON request?
- Create subdomains on the fly with .htaccess (PHP)
- How to add a line break within echo in PHP? [closed]
- Try/Catch block in PHP not catching Exception
- Subtract 1 day with PHP
- Two arrays in foreach loop
- What does “=>” mean in PHP?
- Why is the standard session lifetime 24 minutes (1440 seconds)?
- memory_get_peak_usage() with “real usage”
- PHP combine two associative arrays into one array
- Remove all elements from array that do not start with a certain string
- SimpleXml to string
- PHP 7 interfaces, return type hinting and self
- How to solve `configure: error: Cannot find OpenSSL’s `?
- Lumen Micro Framework => php artisan key:generate
- PHPExcel Make first row bold
- How can I replace newline or \r\n with ?
- How to update Composer in Windows 10
- Inserting NOW() into Database with CodeIgniter’s Active Record
- skip current iteration
- Count number of iterations in a foreach loop
- Formulas to Calculate Geo Proximity
- What is the difference between iconv() and mb_convert_encoding() in PHP?
- How to convert seconds to time format? [duplicate]
- PHP float with 2 decimal places: .00
- json_decode returns NULL after webservice call [duplicate]
- Check if number is decimal
- How to avoid undefined offset
- PHP 7.4 deprecated get_magic_quotes_gpc function alternative
- Simple jQuery, PHP and JSONP example?
- Laravel catch TokenMismatchException
- usort function in a class
- Doctrine 2 Inheritance Mapping with Association
- PHP_AUTH_USER not set?
- jQuery ajax request with json response, how to?
- Is there a limit in PHP to the length of a variable name or function name?
- PHP get pdf file from base64 encoded data string
- How do I find the MIME type of a file with PHP?
- Doctrine 2 update from entity
- Best way to list Alphabetical(A-Z) using PHP
- PHP: How to use monolog to log to console (php://out)?
- How to use Laravel Passport with a custom username column