Log in

View Full Version : Resolved Please help! For loop and Explode($array) issue



olliepop
10-06-2010, 10:12 AM
Hi guys if you know the solution please help me!

This code:


<?php
$array ="1;1;1;1;1;1;1;2;2;1;1;1/1;2;1;1;1;1;1;1;1;1;1;1/1;1;1;1;1;1;1;1;1;1;2;1/1;1;1;2;1;1;1;1;1;2;1;1/1;1;1;1;1;1;1;1;1;1;1;1/1;2;1;1;1;1;1;1;1;1;1;1/1;1;1;1;1;1;1;1;1;1;2;1/1;1;1;1;2;1;1;1;1;1;1;1/2;2;1;1;1;1;1;1;1;1;1;1/1;1;1;1;1;1;1;1;1;1;2;1/1;1;1;1;1;1;1;1;1;1;1;1/1;1;2;1;1;1;1;1;1;1;1;1";
$v1 = explode("/", $array);
for($i=0;$i<12;$i++) {
$v2 = $v1[$i];
$v3 = explode(";", $v2);
for($i=0;$i<12; $i++) {
echo $v3[$i] . " AND ";
}
echo "<br />";
}
?>


Returns

1 AND 1 AND 1 AND 1 AND 1 AND 1 AND 1 AND 2 AND 2 AND 1 AND 1 AND 1 AND

When it should return similar to that 12 times on 12 different rows (as in <br /> rows)

What's wrong? My mind is boggled.

Thank you so much in advance!

-Ollie

olliepop
10-06-2010, 10:16 AM
Resolved. Rediculously stupid of me. The $i variables were the same therefore overlapping - serves me right for copying and pasting the for statement to save a few seconds!