表单 post过来的是字符串类型么?
程序员文章站
2024-02-12 10:18:22
...
1.表单post过来的是字符串类型么?
2.如果是字符串类型,那么下面这段怎么解释,为何不经过类型转换就可以直接相加?Python可不是这样的哦
运行结果:
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虽然是弱类型,但是不会将字段类型默认识别。
传递是什么类型就还是什么类型