How to use php intval function?

藏色散人
Release: 2023-04-05 20:20:01
Original
6028 people have browsed it



##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 )
Copy after login

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; 
?>
Copy after login

Output:

7
Copy after login

intval() function code usage example 2:

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

Output:


1059
Copy after login

intval() function code usage example 3:

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

Output :


64 
52
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template