Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
423 views
in Technique[技术] by (71.8m points)

php - 在PHP中将整数转换为字符串(Converting an integer to a string in PHP)

有没有一种方法可以将整数转换为PHP中的字符串?

  ask by kman99 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...