Oihana PHP

toInt.php

Table of Contents

Functions

toInt()  : int
Converts a value to an integer, defaulting to zero.

Functions

toInt()

Converts a value to an integer, defaulting to zero.

toInt(mixed $value) : int
  • Returns $value unchanged if it is already an int.
  • Casts any other numeric value (numeric string, float, ...) to int.
  • Returns 0 for anything non-numeric.
Parameters
$value : mixed

The value to convert.

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

toInt( 42 )    ; // 42
toInt( "42" )  ; // 42
toInt( 4.9 )   ; // 4
toInt( "abc" ) ; // 0
toInt( null )  ; // 0
author

Marc Alcaraz (ekameleon)

since
1.3.0
Return values
int

The integer value of $value, or 0 if it can't be resolved to a number.

On this page

Search results