小编jim*_*mmy的帖子

在PHP数组中指定数据类型

我有一个包含这个的数组

"postage_cost" => $customer[total_shipping_cost]
Run Code Online (Sandbox Code Playgroud)

当我用var_dump我得到

["postage_cost"]=>
  string(5) "34.54"
Run Code Online (Sandbox Code Playgroud)

在制作数组时如何声明这是一个float而不是一个字符串?我将此数组发送到Web服务,我担心可能会出现一些数据类型混淆.$ customer结果来自MySQL请求.

php arrays types

3
推荐指数
1
解决办法
1538
查看次数

php字符串在不应该的情况下回显为0

我正在编写代码来显示某些产品的价格.如果价格为0则不显示任何内容.

<? if ($book->price_euro != 0) {$europrice = number_format($book->price_eur, 2); echo "€$europrice";}?>
<? if ($book->price_gbp != 0) {$gbpprice = number_format($book->price_gbp, 2); echo "£$gbpprice";}?>
<? if ($book->price_usd != 0) {$usdprice = number_format($book->price_usd, 2); echo "$$usdprice";}?>
Run Code Online (Sandbox Code Playgroud)

这回应"€0.00£33.00 $ 66.00".€价格设置为99.我认为没有任何理由认为这应该为0!难道我做错了什么?语法不好?

php syntax

0
推荐指数
2
解决办法
96
查看次数

标签 统计

php ×2

arrays ×1

syntax ×1

types ×1