PHP code example of renfordt / clamp

1. Go to this page and download the library: Download renfordt/clamp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

renfordt / clamp example snippets


clamp(
    $value, // The value to be clamped
    $min, // The minimum value to clamp to
    $max // The maximum value to clamp to
);

clampMinMax(
    $value, // The value to be clamped
    $min, // The minimum value to clamp to
    $max // The maximum value to clamp to
);

if ($value > $max) {
    return $max;
} elseif ($value < $min) {
    return $min;
}
return $value;