How to force transcoding in php

藏色散人
Release: 2023-03-14 17:38:02
Original
2033 people have browsed it

php forced transcoding method: 1. Transcoding through "(int)$num1;" method; 2. Transcoding through "intval($str);" method; 3. Transcoding through "settype($ num4,"int");" transcoding method.

How to force transcoding in php

#The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.

How to force transcoding in php?

#php Three methods of data type conversion and forced conversion:

(int), (integer): Convert to integer

( float), (double), (real): Convert to floating point type

(string): Convert to string

(bool), (boolean): Convert to Boolean type

(array): Convert to array

(object): Convert to object

The first conversion method: (int) (bool) (float) (string) (array ) (object)

<?php   
$num1=3.14;   
$num2=(int)$num1;   
var_dump($num1); //输出float(3.14)   
var_dump($num2); //输出int(3)   
?>
Copy after login

The second conversion method: intval() floatval() strval()

<?php   
$str="123.9abc";   
$int=intval($str);     //转换后数值:123   
$float=floatval($str); //转换后数值:123.9   
$str=strval($float);   //转换后字符串:"123.9"    
?>
Copy after login

The third conversion method : settype();

<?php   
$num4=12.8;   
$flg=settype($num4,"int");   
var_dump($flg);  //输出bool(true)   
var_dump($num4); //输出int(12)   
?>
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to force transcoding in php. 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