c语言中将整数转换成字符串_如何在PHP中将整数转换为字符串并将字符串转换为整数

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语言中将整数转换成字符串

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值