Thursday, 4 June 2015

Looping through two arrays

I had two result sets (names) loaded into arrays, in this case $result_base and
$result_compare. I needed to check how similar each name was to every other name. In
order to do that, I used a nested while() function like so:

<?php
    while ($base = mysql_fetch_array($result_base))    {
        mysql_data_seek($result_compare, 0);
        while ($compare = mysql_fetch_array($result_compare)){
                   //code do do the comparison
        }
    }

//I'm sure there are more elegant ways to do this, but this worked for me.

?>

0 comments:

Post a Comment