在PHP数组中指定数据类型

jim*_*mmy 3 php arrays types

我有一个包含这个的数组

"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请求.

Fab*_*ler 6

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

请注意,我在键中添加了引号,因为我99.999%确定您没有命名常量total_shipping_cost.PHP对此很好,但是通过激活的错误报告,这可能是一个通知:未定义的常量