PHP-将字符串与HTML文本区域输入的数组元素进行比较



我不明白为什么我的代码不能工作。我想将一个字符串与一个已分解的数据数组进行比较,同时对其进行解析。出于某种原因,我在第一场比赛中得到了一场比赛,但在剩下的比赛中没有。如果有人帮忙,我将不胜感激!我看了又看,但没有找到答案!

通过知道哪个数组元素与哪个字符串匹配,我可以正确存储数据并对其进行计算。这样做的目的是根据以特定格式输入的原始测量数据创建一系列坐标。

我希望我已经解释得足够好了。就像我提到的,我一直在寻找答案,但找不到适合我所做的事情。

谢谢你给我的任何帮助,我很感激!

我尝试过使用in_array,但没有成功,strcmp也没有成功。

Sean

这是我的代码:

<?php
$textArea = explode("r", $_POST['textArea']);
$i = 0;
$j = 0;
foreach ($textArea as $textRows) {
$j = 0;
$textRow = explode(",", $textRows);
foreach ($textRow as $textItem[$i][$j]) {
if ($j == 0) {
if (("TR") == ($textItem[$i][$j])) {
echo("Traverse <br>");
}
if (("CP") == ($textItem[$i][$j])) {
echo("Control <br>");
}
echo("i = $i, j = $j, textItem = " . $textItem[$i][$j] . "<br>");
}
$j++;
}
$i++;
}
echo($textItem[9][0] . "<br>");
echo($textItem[0][0] . "<br>");
echo($textItem[0][3] . "<br>");
echo($textItem[5][6] . "<br>");
$_SESSION['textNum'] = $textItem;
?>

我的测试数据:

CP,100,576.7873,6065.6221,12.542,CP
CP,101,6966.315,2226.4001,9.897,CP
TR,100,1.735,101,1.576,1,1.735,345.9961198,90.04410841,2964.26393,PROP
TR,100,1.735,101,1.576,2,1.735,340.6589997,90.04021446,3080.322203,PROP
TR,100,1.735,101,1.576,3,1.735,351.8639518,90.02168219,5448.892284,PROP
TR,100,1.735,101,1.576,4,1.735,0,90.02469919,5316.851375,PROP
TR,100,1.735,101,1.576,5,1.735,19.26823792,90.02318399,5441.916153,PROP
TR,100,1.735,101,1.576,6,1.735,22.77896709,89.9901807,6138.435694,PROP
TR,100,1.735,101,1.576,7,1.735,5.354105397,89.98465774,7551.171809,PROP
TR,100,1.735,101,1.576,8,1.735,0,90.00156466,6884.324702,PROP
TR,100,1.735,101,1.576,9,1.735,313.0231053,90.03002234,5137.515594,PROP
TR,100,1.735,101,1.576,10,1.735,308.3168227,90.10108781,2655.989628,PROP
TR,100,1.735,101,1.576,11,1.735,340.0064751,11.68927863,757.4152317,PROP
TR,100,1.735,101,1.576,12,1.735,4.661110613,173.921569,776.3980052,PROP
TR,100,1.735,101,1.576,13,1.735,89.44844992,89.87552303,484.2277925,PROP
TR,100,1.735,101,1.576,14,1.735,169.5580845,89.57660413,273.6283687,PROP
TR,100,1.735,101,1.576,15,1.735,273.9971744,90.03246625,331.7785889,PROP

我的当前输出:

Control
i = 0, j = 0, textItem = CP
i = 1, j = 0, textItem = CP
i = 2, j = 0, textItem = TR
i = 3, j = 0, textItem = TR
i = 4, j = 0, textItem = TR
i = 5, j = 0, textItem = TR
i = 6, j = 0, textItem = TR
i = 7, j = 0, textItem = TR
i = 8, j = 0, textItem = TR
i = 9, j = 0, textItem = TR
i = 10, j = 0, textItem = TR
i = 11, j = 0, textItem = TR
i = 12, j = 0, textItem = TR
i = 13, j = 0, textItem = TR
i = 14, j = 0, textItem = TR
i = 15, j = 0, textItem = TR
i = 16, j = 0, textItem = TR
TR
CP
6065.6221
1.735

我想看的内容:

Control
i = 0, j = 0, textItem = CP
Control
i = 1, j = 0, textItem = CP
Traverse
i = 2, j = 0, textItem = TR
Traverse
i = 3, j = 0, textItem = TR
Traverse
i = 4, j = 0, textItem = TR
Traverse
i = 5, j = 0, textItem = TR
Traverse
i = 6, j = 0, textItem = TR
Traverse
i = 7, j = 0, textItem = TR

等等。。。

"n"而不是"r"上分解$_POST阵列,如下所示:

$textArea = explode("n", $_POST['textArea']);
$i = 0;
foreach ($textArea as $textRows) 
{
$j = 0;
$textRow = explode(",", $textRows);
foreach ($textRow as $textItem[$i][$j]) 
{
if ($j == 0) 
{
if (("TR") == ($textItem[$i][$j])) 
{
echo("Traverse <br>");
}
if (("CP") == ($textItem[$i][$j])) 
{
echo("Control <br>");
}
echo("i = $i, j = $j, textItem = " . $textItem[$i][$j] . "<br>");
}
$j++;
}
$i++;
}
echo($textItem[9][0] . "<br>");
echo($textItem[0][0] . "<br>");
echo($textItem[0][3] . "<br>");
echo($textItem[5][6] . "<br>");


请参阅:http://codepad.viper-7.com/XltceQ作为一个工作示例。


输出:

Control 
i = 0, j = 0, textItem = CP
Control 
i = 1, j = 0, textItem = CP
Traverse 
i = 2, j = 0, textItem = TR
Traverse 
i = 3, j = 0, textItem = TR
Traverse 
i = 4, j = 0, textItem = TR
Traverse 
i = 5, j = 0, textItem = TR
Traverse 
i = 6, j = 0, textItem = TR
Traverse 
i = 7, j = 0, textItem = TR
Traverse 
i = 8, j = 0, textItem = TR
Traverse 
i = 9, j = 0, textItem = TR
Traverse 
i = 10, j = 0, textItem = TR
Traverse 
i = 11, j = 0, textItem = TR
Traverse 
i = 12, j = 0, textItem = TR
Traverse 
i = 13, j = 0, textItem = TR
Traverse 
i = 14, j = 0, textItem = TR
Traverse 
i = 15, j = 0, textItem = TR
Traverse 
i = 16, j = 0, textItem = TR
TR
CP
6065.6221
1.735

相关内容

  • 没有找到相关文章

最新更新