1.表单post过来的是字符串类型么?
2.如果是字符串类型,那么下面这段怎么解释,为何不经过类型转换就可以直接相加?Python可不是这样的哦<html>
<?php
// create short variable names
$tireqty = $_POST['tireqty'];
$oilqty = $_POST['oilqty'];
$sparkqty = $_POST['sparkqty'];
// create constant names
define ('TIREPRICE',100);
define ('OILPRICE',10);
define ('SPARKPRICE',4);
?>
<head>
<title>Bob's Auto Parts - Order Result</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
<?php
//echo '<p>Order processed.</p>';
echo '<p>Order processed at '.date('H:i , jS F Y').'</p>'; // 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.<br/>";
echo '<p>Your order is as follow: </p>';
echo $tireqty. ' tires. <br/>';
echo $oilqty. ' bottles of oil<br/>';
echo $sparkqty. ' spark plugs<br/>';
// calc total items ordered
$totalqty = 0;
$totalqty = $tireqty + $oilqty + $sparkqty;
if ($totalqty == 0)
{
echo 'You did not order anything on the previous page!<br/>';
}
else
{
echo "Items ordered: $totalqty <br/>";
// calc total amount
$toatlamount = 0;
$toatlamount = $tireqty * TIREPRICE + $oilqty * OILPRICE + $sparkqty * SPARKPRICE;
echo 'Subtotal: $'.number_format($toatlamount,2).'<br/>';
// calc total tax
$taxrate = 0.10;
$totaltaxrate = 0;
$totaltaxrate = $toatlamount * 0.10;
echo 'Total tax: $'.number_format($totaltaxrate,2).'<br/>';
}
}
?>
</body>
</html>运行结果:Bob's Auto Parts
Order Results
Order processed at 17:33 , 15th April 2013one of your input is type string.Your order is as follow: 1 tires.
2 bottles of oil
3 spark plugs
Items ordered: 6
Subtotal: $132.00
Total tax: $13.20
PHPString
2.如果是字符串类型,那么下面这段怎么解释,为何不经过类型转换就可以直接相加?Python可不是这样的哦<html>
<?php
// create short variable names
$tireqty = $_POST['tireqty'];
$oilqty = $_POST['oilqty'];
$sparkqty = $_POST['sparkqty'];
// create constant names
define ('TIREPRICE',100);
define ('OILPRICE',10);
define ('SPARKPRICE',4);
?>
<head>
<title>Bob's Auto Parts - Order Result</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
<?php
//echo '<p>Order processed.</p>';
echo '<p>Order processed at '.date('H:i , jS F Y').'</p>'; // 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.<br/>";
echo '<p>Your order is as follow: </p>';
echo $tireqty. ' tires. <br/>';
echo $oilqty. ' bottles of oil<br/>';
echo $sparkqty. ' spark plugs<br/>';
// calc total items ordered
$totalqty = 0;
$totalqty = $tireqty + $oilqty + $sparkqty;
if ($totalqty == 0)
{
echo 'You did not order anything on the previous page!<br/>';
}
else
{
echo "Items ordered: $totalqty <br/>";
// calc total amount
$toatlamount = 0;
$toatlamount = $tireqty * TIREPRICE + $oilqty * OILPRICE + $sparkqty * SPARKPRICE;
echo 'Subtotal: $'.number_format($toatlamount,2).'<br/>';
// calc total tax
$taxrate = 0.10;
$totaltaxrate = 0;
$totaltaxrate = $toatlamount * 0.10;
echo 'Total tax: $'.number_format($totaltaxrate,2).'<br/>';
}
}
?>
</body>
</html>运行结果:Bob's Auto Parts
Order Results
Order processed at 17:33 , 15th April 2013one of your input is type string.Your order is as follow: 1 tires.
2 bottles of oil
3 spark plugs
Items ordered: 6
Subtotal: $132.00
Total tax: $13.20
PHPString
解决方案 »
- 关于安全性的一些疑问
- 新手php程序员,关于 Class 'SoapClient' not found in的错误,求解答
- 大家都是怎么用PHP处理64位数值的?
- MySQL Enterprise Server不再开源,会多大程度上影响了php的发展。???
- 帮忙啊
- 求php与mysql开发网站的电子书
- Mysql数据库28row/s写入速度,慢么??
- 两个下拉列表关联的问题
- 这个问题一直伴我过了很久,仍未解决,请帮我,好吗?在线等待
- 为什么ie可以正常接收到js生成的表单内容,chrome却不行
- 自己编写了个PHP扩展模块,在扩展模块中需要调用另外一个动态库,也是自己写的。Linux下怎么
- 页面执行时间很长,如何实时给客户端输出程序运行的指示信息?
但PHP的字符串连接符是 . 号,如果你用 '1'+'2'; 它当然明白你是想相加,而不是相连。因此结果自然是3,而不是'12'。甚至你用 '1'+'ssss' 也会得到数字1
2. 有很多语言有自动Cast的功能的。