PHP - intval
Trieda
Metóda - intval
(PHP 4, PHP 5, PHP 7)
Determines the integer value of a given parameter with a conversion to a specified base (radix).
Note: Calling this function with an object given as the
$var parameter will result into emitting an error of the
E_NOTICE level and returning 1.
Procedurálne
- function intval (mixed $var, int $base = 10) : int
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| $var | mixed | The input value, whose integer value should be determined. | |
| $base | int | 10 | The base (radix) of the numerical system in which the input value is represented. Note: This parameter will take effect only if the input value is string. If value |
Mávratovej hodnoty
Vracia: int
The resulting integer value, if conversion succeeds, 0
otherwise.
Passing an empty array will return 0, for a non-empty array will
return 1.
Príklady
<?php
echo intval(11); // Output: 11
echo intval('11'); // Output: 11
echo intval('+11'); // Output: 11
echo intval('-11'); // Output: -11
echo intval('011'); // Output: 11
echo intval(011); // Output: 9
echo intval(1e10); // Output: 1
echo intval('1e10'); // Output: 10000000000
echo intval(5.2); // Output: 5
echo intval('0x1A'); // Output: 0
echo intval(0x1a); // Output: 26
echo intval(array()); // Output: 0
echo intval(array(50)); // Output: 1
Súvisiace manuály
- function boolval () : boolean
- function is_numeric (mixed $var) : bool
