Home  >  Article  >  Backend Development  >  How to use php intval function?

How to use php intval function?

藏色散人
藏色散人Original
2019-04-13 15:52:596029browse



##This article mainly introduces how to use

php intval function, then The intval() function is a built-in function in PHP that returns the integer value of a variable.

Syntax:

int intval ( $var, $base )

Parameters:

This function accepts two parameters, one of which is required and the other One is optional.

The parameters are described below:

$var: This is a required parameter and is used as a variable that needs to be converted to an integer value.

$base: It is an optional parameter that specifies the base on which $var is converted to the corresponding integer. If $base is not specified. If $var contains 0x (or 0X) as a prefix, base is treated as 16. If $var contains 0, the base is 8; otherwise, the base is 10.

Return value:

Returns the corresponding integer value of $var.

intval() function code usage example 1:

<?php 
$var = &#39;7.423&#39;; 
$int_value = intval($var); 
echo $int_value; 
?>

Output:

7

intval() function code usage example 2:

<?php 
$var = 0x423; 
$int_value = intval($var); 
echo $int_value; 
?>

Output:


1059

intval() function code usage example 3:

<?php 
$var = "64"; 
echo intval($var)."\n".intval($var, 8); 
  
?>

Output :


64 
52

Related recommendations: "

PHP Tutorial"



# #

The above is the detailed content of How to use php intval function?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn