Breakdown of script :- // We need to know how many rows there are in the '$rows' array, // so we can loop through each one looking at all of the values, // which is held in $max_rows $max_rows = count($rows); // Firstly, we loop around every instance of $rows, using 'foreach'. // The key to the $rows array, i.e. 0, 1, 2, 3, etc is loaded into // $array_key and the value is loaded in $array_value. // // Remember that $array_value is an array itself, but PHP // is quite happy with this as it is a 'loosely typed' language, so // you can load any type of value into any variable // // There are 2 loops going on in the code, one to take us through each // row as a main loop, and another to go back through all the rows at the // time, comparing the row to all of the other rows // // If we were to look inside the loops, we would see something like this :- // // MAIN LOOP SUB-LOOP // current row -> compare to // 0 1 // 0 2 // 0 3 // 1 0 // 1 2 // 1 3 // 2 0 // 2 1 // 2 3 // 3 0 // 3 1 // 3 2 // // Notice that we never compare the current row to itself, we simply // step over it // foreach ($rows as $array_key => $array_value) { // lets output a message to say which array row we're currently working on // We know which one it is, because we loaded that information in // $array_key, i.e. 0, 1, 2, etc echo "<br>Curr row = " . $array_key . " - <br>\n"; // Now the good bit // We have to loop round all of the rows (in $rows) independently of the loop // we're doing in our 'foreach' above, but we must not compare the row to // inself // // First of all, we set a counter, called $i, to zero // We keep looping round until we get to the end of the rows, by looking at // the value of $max_rows for ($i = 0; $i < $max_rows; $i++) { // In this statement we check to see if the row we're currently // checking in our 'for' loop, is the same row as the row we're on // in our 'foreach' loop. Remember, we must not compare a row to itself if ($array_key <> $i) { // Compare the elements in $array_value, which holds the current // $rows array to the current $rows in our 'for' loop, and store the results // in $common $common = array_intersect($array_value, $rows[$i]); // Loop round each of the matching values, in $common, and output them foreach ($common as $key => $value) { echo "Key: $key; Value: $value\n"; } echo "<BR>"; } } } -----Original Message----- From: php-objects@xxxxxxxxxxxxxxx [mailto:php-objects@xxxxxxxxxxxxxxx] On Behalf Of Robert Barker Sent: 17 January 2008 18:11 To: php-objects@xxxxxxxxxxxxxxx Subject: RE: HOW DO I CREATE A LOOP CRAWLER? EXCELLENT WORK ROB. THANK YOU VERY MUCH. *********************************************************************************** Any opinions expressed in email are those of the individual and not necessarily those of the company. This email and any files transmitted with it are confidential and solely for the use of the intended recipient or entity to whom they are addressed. It may contain material protected by attorney-client privilege. If you are not the intended recipient, or a person responsible for delivering to the intended recipient, be advised that you have received this email in error and that any use is strictly prohibited. Random House Group + 44 (0) 20 7840 8400 http://www.randomhouse.co.uk http://www.booksattransworld.co.uk http://www.kidsatrandomhouse.co.uk Generic email address - enquiries@xxxxxxxxxxxxxxxxx Name & Registered Office: THE RANDOM HOUSE GROUP LIMITED 20 VAUXHALL BRIDGE ROAD LONDON SW1V 2SA Random House Group Ltd is registered in the United Kingdom with company No. 00954009, VAT number 102838980 ***********************************************************************************