English 中文(简体)
PHP 描述错误
原标题:PHP script misbehaving
  • 时间:2011-10-16 19:02:33
  •  标签:
  • php

我有一份小篇文字,界定了一个称为<代码>的变量。 这份文字并非按我的意图行事,因为某些部法的产品显示与其他部门法典有关的价格。 因此,我假定,我最初把这一点放在一起的方式有些错。

我要问的是,谁会发现一个问题,或提出如何改进以下简明的网址:

// Cost plus 2.5%
if ($prDept = (204 || 205 || 209 || 1501 || 1601 )) {
    if ($_SESSION[ tax ] == "on" || !isset($_SESSION[ tax ]))
        $prPrice = ((($prCost1 / 1.14) * 1.025) * 1.14);
    else if ($_SESSION[ tax ] == "off" && $prTaxable == "1")
        $prPrice = ($prCost1 * 1.025);
    else if ($_SESSION[ tax ] == "off" && $prTaxable == "0")
        $prPrice = (($prCost1 / 1.14) * 1.025);

iii

最佳回答
$prDept = (204 || 205 || 209 || 1501 || 1601)

这并不是购买力平价中的这种工作。 确实需要看好......

$prDept == 204 || $prDept == 205 || $prDept == 209 || $prDept == 1501 || $prDept == 1601

或替代

in_array($prDept, array(204, 205, 209, 1501, 1601))
问题回答
if ($prDept == 204 || $prDept == 205 || $prDept == 209 || $prDept == 1501 || $prDept == 1601) {
    if ($_SESSION[ tax ] == "on" || !isset($_SESSION[ tax ])) {
          $prPrice = ((($prCost1 / 1.14) * 1.025) * 1.14);
    } else if ($_SESSION[ tax ] == "off" && $prTaxable == "1") {
          $prPrice = ($prCost1 * 1.025);
    } else if ($_SESSION[ tax ] == "off" && $prTaxable == "0") {
          $prPrice = (($prCost1 / 1.14) * 1.025);
    }   
}

I would write this as:

$departments = array(204 , 205 , 209 ,1501, 1601);

if (in_array($prDept, $departments)) {
 ...
}




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签