Same array indexes - sequential comparison

ぐ巨炮叔叔 提交于 2019-12-13 03:34:37

问题


I have following problem, kindly help solve this by looping/recursion/function or any other suitable method. The problem is the following:

if (($a[0]==$a[1]) && ($a[1]==$a[2])) do operation1
else if(($a[0]==$a[1])&& ($a[1]!==$a[2])) do operation2

However, I tried by many approaches, one of them is:

for($x=1; $x<$arrlength; $x++)   {   
$a = (strncasecmp($sort[$x],$sort[$x++],strpos($sort[$x],'-')) == 0);

for ($y = 2; $y < $x; $y++)
{
$b = (strncasecmp($a,$sort[$y+1],strpos($a,'-')) == 0);
  switch ($b)
{
case ($b == true)  : 

echo  " <TH class=\"tr1 td26\"><P class=\"p16 ft4\">".substr($sort[$y],0,strpos($sort[$y],'-'))."</P>";

echo "<P class=\"p12 ft4\">".ltrim(substr($sort[$b],strpos($sort[$b],'-')),"-")."</p></TH>";
echo  " <TH class=\"tr1 td26\"><P class=\"p12 ft4\">".ltrim(substr($sort[$y],strpos($sort[$y],'-')),"-")."</P></TH>";
break;

}
}     }

This problem is that the solution didn't work and ltrim the values properly.

来源:https://stackoverflow.com/questions/20565011/same-array-indexes-sequential-comparison

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!