Hello Guys, I am stuck again. I hope someone can help me out here please.
Let me start by telling you the idea;
The plan is to find the common element(number) in each row. The idea is two-fold. The first is, to write the LOOP to get $rows[0] start and to go through and intersect with the rest of the rows in the table, that is, to intersect with $rows[1], $rows[2], $rows[3] ......etc and not just stop at $rows[0] and $rows[1]
The second idea is after getting to the end of intercepting with each row; then the whole process begins again but this time $rows[0] is ignored and the process starts at $rows[1] as the main interceptor to repeat the process, after that $rows[2] and so on and so forth. I call it the "crawler."
The following is an example of the array I am working on;
$rows = array();
$rows[0] = array(10,12,55,26);
$rows[1] = array(4,11,34,48);
$rows[2] = array(1,20,43,55) ;
$rows[3] = array(5,13,14,87);
$rows[4] = array(30,42,55,69);
$rows[5] = array(18,3,13,70);
$rows[6] = array(1,42,43,48);
$rows[7] = array(9,11,44,48);
$rows[8] = array(3,10,33,55) ;
$rows[9] = array(5,10,15,86);
$rows[10] = array(10,15,55,69);
$rows[11] = array(2,3,17,70);
$rows[12] = array(17,11,33,48);
$rows[13] = array(10,42,55,69);
$rows[14] = array(61,13,23,70);
$rows[15] = array(71,12,13,48);
$rows[16] = array(9,31,34,38);
$rows[17] = array(3,20,13,55) ;
$rows[18] = array(5,12,25,87);
$rows[19] = array(20,42,55,69);
$rows[20] = array(1,4,14,70);
The script I am working with is the following but it is not working. I am getting some
really strange results.
$max_rows = count($rows) ;
foreach ($rows as $array_key => $array_value) {
echo "<br>Curr row = " . $array_key . " - <br>\n";
for ($i = 0; $i < $max_rows; $i++) {
if ($array_key <> $i) {
$common = array_intersect( $array_value, $rows[$i]);
foreach ($common as $key => $value) {
echo "Key: $key; Value: $value\n";
}
echo "<BR>";
}
}
}
?>
The following is a snippet of the STRANGE results I am getting;
Curr row = 0 -
Key: 2; Value: 55
Key: 2; Value: 55
Key: 0; Value: 10 Key: 2; Value: 55
Key: 0; Value: 10
Key: 0; Value: 10 Key: 2; Value: 55
Key: 1; Value: 12
Key: 2; Value: 55
Key: 1; Value: 12
Key: 0; Value: 10 Key: 2; Value: 55
Curr row = 1 -
Key: 3; Value: 48
Key: 1; Value: 11 Key: 3; Value: 48
Key: 1; Value: 11 Key: 3; Value: 48
Key: 3; Value: 48
Key: 2; Value: 34
Key: 0; Value: 4
Key: 3; Value: 48
.
.
.
.etc. etc
As you can see the results are nowhere near what I can see visually. For example a visual view of $rows[0] and $rows[1] would be == 0; $rows[0] and $rows[2] == 55; $rows[0] and $rows[3] == 0; etc. So far I am not getting anything like that from the script. Can anyone help me out to improve upon the script please.