一个新手尝试在SO上的Q.

时间:2010-10-27 14:21:06

标签: php

我有一点新手的故障。

我有这样的事情:

// Assign Device ID
if ($line == "IMEI 358998018395510\r\n"){
 $device_id = 1;
 }elseif($line == "IMEI 352924028650492\r\n"){
 $device_id2 = 3;
}
 ........
 ........
 if (fwrite($outFile,$device_id or device_id2. ",". $date.",".$line)===FALSE){

我希望能够确定device_id或device_id 2的哪一个变量最终是结果,所以我可以将它附加到上一行的fwrite语句中。有人可以说明一下吗?

2 个答案:

答案 0 :(得分:2)

您只需使用相同的变量:

// Assign Device ID 
if ($line == "IMEI 358998018395510\r\n"){ 
 $device_id = 1; 
 }elseif($line == "IMEI 352924028650492\r\n"){ 
 $device_id = 3; 
} 
 ........ 
 ........ 
 if (fwrite($outFile,$device_id . ",". $date.",".$line)===FALSE){ 

答案 1 :(得分:1)

此?

// Assign Device ID
if ($line == "IMEI 358998018395510\r\n"){
 $device_id = 1;
 }elseif($line == "IMEI 352924028650492\r\n"){
 $device_id = 3;
}
 ........
 ........
 if (fwrite($outFile, $device_id . "," . $date . "," . $line)===FALSE){

或者

$resultId = $device_id == null : $device_id2 ? $device_id;
if (fwrite($outFile, $resultId . "," . $date . "," . $line)===FALSE){