Php 在if语句中使用分解数组
第一个帖子。我在这里找了一整天想找出一个问题 我正在使用表单上载一个.txt,其中包含以下格式的数组: “var1”、“var2”、“var3”、“var4”等 这是我的代码:Php 在if语句中使用分解数组,php,arrays,if-statement,explode,Php,Arrays,If Statement,Explode,第一个帖子。我在这里找了一整天想找出一个问题 我正在使用表单上载一个.txt,其中包含以下格式的数组: “var1”、“var2”、“var3”、“var4”等 这是我的代码: <?php $file = $_FILES['uploaded_file']['tmp_name']; $file2 = nl2br(file_get_contents($file)); $file3 = str_replace('"' , '' , $file2); $file4 = str_replace('
<?php
$file = $_FILES['uploaded_file']['tmp_name'];
$file2 = nl2br(file_get_contents($file));
$file3 = str_replace('"' , '' , $file2);
$file4 = str_replace('ÿþ' , '' , $file3);
$line_break = explode("<br />" , $file4);
$topchange=105;
foreach ($line_break as $final1) {
$final2 = explode("," , $final1);
$regex = '#\((([^()]+|(?R))*)\)#';
preg_match($regex, $final1, $match);
if($final2[4] == "DF") {
$type == "DF";
} else { $type == "S"; }
echo "<div style='position:absolute;TOP:". $topchange .";LEFT:395;'>". $final2[1] ."</div>";
echo "<div style='position:absolute;TOP:". $topchange .";LEFT:446;'>". $final2[3] ."</div>";
echo "<div style='position:absolute;TOP:". $topchange .";LEFT:365;'>". $match[0] ."</div>";
echo "<div style='position:absolute;TOP:". $topchange .";LEFT:335;'>". $type ."</div>";
echo "<div style='position:absolute;TOP:". $topchange .";LEFT:520;'>". $final2[6] ."</div>";
$changeamt = 24.2;
$topchange = $topchange + $changeamt;
}
?>
如果必须分配而不进行比较,则代码如下所示:
if($final2[4] == "DF") {
$type == "DF";
} else {
$type == "S";
}
你应该这样做:
$type = "S";
if($final2[4] == "DF") {
$type = "DF";
}
在您的if中,如果必须分配且不进行比较,您的代码如下所示:
if($final2[4] == "DF") {
$type == "DF";
} else {
$type == "S";
}
你应该这样做:
$type = "S";
if($final2[4] == "DF") {
$type = "DF";
}
在本例中,您分配$df,但它可能有其他值。正确的代码是:$df=($final2[4]!=='df')?'S':'DF';在本例中,您分配$df,但它可能有其他值。正确的代码是:$df=($final2[4]!=='df')?'S':'DF';