Home  >  Article  >  Backend Development  >  How to convert numbers to characters in php?

How to convert numbers to characters in php?

青灯夜游
青灯夜游Original
2020-07-15 18:20:233949browse

How to convert numbers to characters in php: 1. Use forced data type conversion to convert the number type to a string type; 2. Use the strval() function to convert the number to a string and return the string type value.

How to convert numbers to characters in php?

Method 1: Use forced data type conversion

(string): Convert to string

Example:

<?php
header("Content-Type: text/html; charset=utf-8");
$num1=3.14;   
$num2=(string)$num1;   
var_dump($num1); //输出float 3.14   
var_dump($num2); //输出string &#39;3.14&#39; (length=4)
?>

Method 2: Use the strval() function

strval() — Get the string value of the variable.

Example:

<?php
header("Content-Type: text/html; charset=utf-8");
$num1=3.14;   
$num2=strval($num1);   
var_dump($num1); 
var_dump($num2); 
?>

Recommended learning:php tutorial

The above is the detailed content of How to convert numbers to characters in php?. 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