您可以使用strval()
函数将数字转换为字符串.
从维护的Angular 来看,这显然是你想要做的,而不是其他一些更深奥的答案.当然,这取决于你的背景.
$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";