c语言中将整数转换成字符串
Conversion from integer to string and from string to integer are common operations in most applications such as C++. PHP has its uniqueness in language and standard library design. In this post, we will check methods to convert integers to strings and vice versa.
从整数到字符串以及从字符串到整数的转换是大多数应用程序(例如C ++)中的常见操作。 PHP在语言和标准库设计方面具有独特性。 在本文中,我们将检查将整数转换为字符串,反之亦然的方法。
在PHP中将字符串转换为int (Convert string to int in PHP)
You can cast a string to int using the (int)
cast directly. PHP provides a standard library function intval() to convert strings to integers. intval()
can do the integer converting using specified base too.
您可以直接使用(int)
强制转换将字符串强制转换为int。 PHP提供了一个标准的库函数intval()来将字符串转换为整数。 intval()
也可以使用指定的基数进行整数转换。
One example usage is as follows.
一种示例用法如下。
$ php -a
Interactive mode enabled
php > $str = "8";
php > $n = (int)$str;
php > echo $n;
8
php > $m = intval($str);
php > echo $m;
8
在PHP中将int转换为字符串 (Convert int to string in PHP)
You can do casting too using (string)
cast. PHP also provides at least 2 common functions for converting integers to strings: strval() and sprintf().
您也可以使用(string)
强制类型转换。 PHP还提供至少2个将整数转换为字符串的常用函数: strval()和sprintf() 。
One example usage is as follows.
一种示例用法如下。
$ php -a
Interactive mode enabled
php > $n = 8;
php > $str = (string)$n;
php > echo $str;
8
php > echo strval($n);
8
php > echo sprintf("%d", $n);
8
翻译自: https://www.systutorials.com/how-to-convert-integers-to-strings-and-strings-to-integers-in-php/
c语言中将整数转换成字符串