Oihana PHP

clamp.php

Table of Contents

Functions

clamp()  : int|float
Bounds a number value between two numbers.

Functions

clamp()

Bounds a number value between two numbers.

clamp(int|float $value, int|float $min, int|float $max) : int|float

This is a clarified alias of clip() ; both names are kept for convenience.

Parameters
$value : int|float

The value to clamp.

$min : int|float

The minimum value of the range.

$max : int|float

The maximum value of the range.

Tags
example
use function oihana\core\numbers\clamp;

clamp( 4  , 5 , 10 ) ; // Returns 5
clamp( 12 , 5 , 10 ) ; // Returns 10
clamp( 6  , 5 , 10 ) ; // Returns 6
author

Marc Alcaraz (ekameleon)

since
1.0.9
Return values
int|float

A value bounded between $min and $max.

On this page

Search results