How to convert numbers to string type in php
php method to convert numbers to strings: 1. Add the target type "(string)" enclosed in parentheses before the numeric variable to be converted, the syntax is "(string)$num"; 2 , use strval() function, syntax "strval($num)".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php converts numbers For string type
#Method 1: Add the target type enclosed in parentheses "(string)
"# before the numeric variable to be converted.
( string)
: It is forced to convert to string type;
<?php header("Content-type:text/html;charset=utf-8"); $num = 12354; echo '原变量类型为:' . gettype($num) . '<br>'; $str = (string)$num; echo '转换后的变量类型为:' . gettype($str) . '<br><br>'; $num = 123.54; echo '原变量类型为:' . gettype($num) . '<br>'; $str = (string)$num; echo '转换后的变量类型为:' . gettype($str) . '<br><br>'; ?>
strval() function is used to get the string value of a variable.
<?php header("Content-type:text/html;charset=utf-8"); $num = 3.1415; echo '原变量类型为:' . gettype($num) . '<br>'; $str = strval($num); echo '转换后的变量类型为:' . gettype($str) . '<br><br>'; $num = 31415; echo '原变量类型为:' . gettype($num) . '<br>'; $str = strval($num); echo '转换后的变量类型为:' . gettype($str) . '<br><br>'; ?>
Recommended learning: "
The above is the detailed content of How to convert numbers to string type in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Linux new version
SublimeText3 Linux latest version

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
