数组中带有逗号的货币格式

发布于 2025-01-06 03:56:02 字数 523 浏览 0 评论 0原文

我的 PHPstorm 数组格式不稳定。令人惊讶的是,我没有找到如何格式化该数组的直接答案。我已经尝试过以下操作,令我惊讶的是单引号不起作用,然后是其他两个,但没有运气......

$array = array(’$2,000,000’,’$3,000,000’,’$4,000,000’);
$array = array("$2,000,000","$3,000,000","$4,000,000");
$array = array("\$2,000,000","\$3,000,000","\$4,000,000");

手册中没有可以转义的逗号。鉴于该数组仅用于 HTML 输出,我可以放置,

$array = array("&#362&#44000&#44000","&#36$3&#44000&#44000","&#364&#44000&#44000");

但我想了解如何正确执行

My PHPstorm is throwing a wobbly with the formats of an array. Surprsingly I've found no direct answer to how to have this array formatted. I've tried the following, I'm surprised the single quotes don't work and then the other two but no luck...

$array = array(’$2,000,000’,’$3,000,000’,’$4,000,000’);
$array = array("$2,000,000","$3,000,000","$4,000,000");
$array = array("\$2,000,000","\$3,000,000","\$4,000,000");

The manual doesn't have commas as escapable. Given that the array is for HTML ouput only I could put

$array = array("Ūꯠꯠ","$$3ꯠꯠ","Ŭꯠꯠ");

but i want to LEARN HOW TO DO IT properly!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

灼痛 2025-01-13 03:56:02

单引号不起作用,因为这里的不是单引号,而是弯撇号:

// Incorrect - not real single quotes:
$array = array(’$2,000,000’,’$3,000,000’,’$4,000,000’);

// Correct single quotes:
$array = array('$2,000,000','$3,000,000','$4,000,000');

假设您可能已从某处复制/粘贴了此内容,那么在使用代码时请始终小心弯引号。一些 CMS 和框架会将它们转换为显示目的,但这样做会破坏复制/粘贴的代码。

The single quotes don't work because what you have here are NOT single quotes, but rather curly apostrophes:

// Incorrect - not real single quotes:
$array = array(’$2,000,000’,’$3,000,000’,’$4,000,000’);

// Correct single quotes:
$array = array('$2,000,000','$3,000,000','$4,000,000');

Assuming you may have copy/pasted this from somewhere, always beware curly quotes when working with code. Some CMS' and frameworks will convert them for display purposes, but doing so breaks the code for copy/pasters.

总攻大人 2025-01-13 03:56:02

您使用了不正确的引号:

$array = array(’$2,000,000’,’$3,000,000’,’$4,000,000’);
               ^--        ^-^---       ^---etc....

这些不是正确的引号,应该是 '" 字符。

You're using incorrect quotes:

$array = array(’$2,000,000’,’$3,000,000’,’$4,000,000’);
               ^--        ^-^---       ^---etc....

Those aren't proper quotes, and should be a ' or " character instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文