Werid Output from a foreach statement
Posted: Wed Jan 03, 2007 6:11 pm
I have this:
Which is the $other in the code below:
And I keep getting:
When I should be getting:
I just cant figure out why. Can some one please help!
Code: Select all
Code: Select all
<table> <?php
function OddOrEven($intNumber){
if ($intNumber % 2 == 0 ){
//your number is even
return "Even";
} else {
return "Odd";
}
}
$rowcount = 0;
$new_tags = split('~', $other);
$trans = array();
foreach($new_tags as $tag){
$split = split("]",$tag);
$split[0] = str_replace('[','',$split[0]);
$split[0] = trim($split[0]);
$split[1] = trim($split[1]);
$trans[] = array($split[0],$split[1]);
}
foreach($trans as $out){
$rowcount = $rowcount + 1;
$oddoreven = OddOrEven($rowcount);
if($oddoreven=="Odd"){
$output.='
<tr>
<td align="right">'.$out[0].':</td>
<td colspan="3" style="padding-left:7px;">'.$out[1].'</td>
</tr> ';
} else {
$output.='
<tr>
<td align="right" bgcolor="#e9e9e9">'.$out[0].':</td>
<td colspan="3" bgcolor="#e9e9e9" style="padding-left:7px;">'.$out[1].'</td>
</tr>';
}
print($output);
}
?>
</table>Code: Select all
Color: Green
Color: Green
Year: 2006
Color: Green
Year: 2006
Intel: 3Code: Select all
Color: Green
Year: 2006
Intel: 3