php sparkpost,表单 post过来的是字符串类型么?

1.表单post过来的是字符串类型么?

2.如果是字符串类型,那么下面这段怎么解释,为何不经过类型转换就可以直接相加?Python可不是这样的哦

Bob's Auto Parts - Order Result

Bob's Auto Parts

Order Results Order processed.'; echo '

Order processed at '.date('H:i , jS F Y').''; // overcome not integer number if (is_string($tireqty) == True or is_string($oilqty) == True or is_string($sparkqty) == True) { echo "one of your input is type string.

"; echo '

Your order is as follow:'; echo $tireqty. ' tires.

'; echo $oilqty. ' bottles of oil

'; echo $sparkqty. ' spark plugs

'; // calc total items ordered $totalqty = 0; $totalqty = $tireqty + $oilqty + $sparkqty; if ($totalqty == 0) { echo 'You did not order anything on the previous page!

'; } else { echo "Items ordered: $totalqty

"; // calc total amount $toatlamount = 0; $toatlamount = $tireqty * TIREPRICE + $oilqty * OILPRICE + $sparkqty * SPARKPRICE; echo 'Subtotal: $'.number_format($toatlamount,2).'

'; // calc total tax $taxrate = 0.10; $totaltaxrate = 0; $totaltaxrate = $toatlamount * 0.10; echo 'Total tax: $'.number_format($totaltaxrate,2).'

'; } } ?>

运行结果:

Bob's Auto PartsOrder ResultsOrder processed at 17:33 , 15th April 2013one of your input is type string.Your order is as follow: 1 tires. 2 bottles of oil3 spark plugsItems ordered: 6 Subtotal: $132.00Total tax: $13.20

回复讨论(解决方案)

python的字符串连接符和算数相加都是+号,如果你 '1'+'2', python没法明白你的意思,到底相加还是相连?它可不能自作主张,只好严格按类型运算。

但PHP的字符串连接符是 . 号,如果你用 '1'+'2'; 它当然明白你是想相加,而不是相连。因此结果自然是3,而不是'12'。甚至你用 '1'+'ssss' 也会得到数字1

1. 是字符串类型。

2. 有很多语言有自动Cast的功能的。

呵呵呵 刚开始接触弱类型语言的时候都有这类想发,习惯就好了...

python是弱类型,是不需要声明字段属性的,python虽然是弱类型,但是不会将字段类型默认识别。

传递是什么类型就还是什么类型

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值