Specify data type in PHP array
I have an array containing this
"postage_cost" => $customer[total_shipping_cost]
when i use var_dump
i get
["postage_cost"]=>
string(5) "34.54"
How can I declare that it is a float and not a string when creating an array? I am posting this array to a web service and I am afraid there might be some data type confusion. The $ customer result is a MySQL query.
+3
source to share
3 answers
"postage_cost" => (float) $customer['total_shipping_cost']
Note that I have added quotes to the key because I am up to 99.999% sure that you do not have a constant with a name total_shipping_cost
. PHP is kind to this, but with error reporting enabled it would be Note: undefined constant
+6
source to share