本文介绍了在 PHP 中将整数转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
有没有办法在 PHP 中将整数转换为字符串?
Is there a way to convert an integer to a string in PHP?
推荐答案
您可以使用 strval()
函数将数字转换为字符串.
You can use the strval()
function to convert a number to a string.
从维护的角度来看,您想要做的事情很明显,而不是其他一些更深奥的答案.当然,这取决于您的上下文.
From a maintenance perspective its obvious what you are trying to do rather than some of the other more esoteric answers. Of course, it depends on your context.
$var = 5;
// Inline variable parsing
echo "I'd like {$var} waffles"; // = I'd like 5 waffles
// String concatenation
echo "I'd like ".$var." waffles"; // I'd like 5 waffles
// The two examples above have the same end value...
// ... And so do the two below
// Explicit cast
$items = (string)$var; // $items === "5";
// Function call
$items = strval($var); // $items === "5";
这篇关于在 PHP 中将整数转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!