问题
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