You can use the strval()
function to convert a number to a string.
(您可以使用strval()
函数将数字转换为字符串。)
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
// Explicit cast
$items = (string)$var; // $items === "5";
// Function call
$items = strval($var); // $items === "5";
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…