简体   繁体   中英

How to format number as currency in array PHP?

Im having trouble with this code - getting a 500 error, I need to format as currency for the values in an array. But getting stuck:

If I use round() - it will work - but it just rounds the number, which is not what Im after.

$cart[] = array('name' => $message->name, 'values' => array(round($delivery->revenue), $delivery->uniqConversions));

But if I try to use money_format, it does not work:

$cart[] = array('name' => $message->name, 'values' => array(money_format('$%i', ($delivery->revenue), $delivery->uniqConversions));

Any Ideas?

Its because you are missing ) at the end of your line:

$cart[] = array('name' => $message->name, 'values' => array(money_format('$%i', ($delivery->revenue), $delivery->uniqConversions)));

Thats why you are getting Error 500.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM