I have two arrays and need to perform the array_diff function.  However,
since it is broken in 4.x, I'm trying to get the same outcome.  Due to the
nature of my call to this function the selected is always going to be a
number of items selected from the connections.  For some reason the outcome
does not work sometimes.  The following is the code I set up.  Please excuse
any poor abilities on my part for constructing the code efficiently (I'm
pretty new at this stuff)....

function array_dif($slctd, $connctns)
        {
                for($i = 0; $i < count($slctd); $i++)
                {
                        if(preg_match("/\b$slctd[$i]\b/", "$connctns[$i]"))
                        {
                                unset($connctns[$i]);
                                unset($slctd[$i]);
                                echo "match0";
                        }
                        for($j = 1 ; $j < count($connctns); $j++)
                        {
                                if(preg_match("/\b$slctd[$i]\b/", "$connctns[$j]"))
                                {
                                        unset($connctns[$j]);
                                        unset($slctd[$i]);
                                        echo "match[$i]";
                                }
                        }
                }
                $k = array_merge($connctns, $selected);
                return $k;
        }

$selected = preg_split("/\,/", $pltoload);
echo "<TH>Select:<TH>";
echo '<BR><select multiple name="plutoload[]">';

for ($i = 0; $i < count($selected); $i++)
{
                echo '<option selected value="', "$selected[$i]", '">', 
"$selected[$i]";
                $trimselect = array();
                array_push($trimselect, (trim($selected[$i])));
}
$unselect = array_dif($trimselect, $connections);
for ($s = 0; $s < count($unselect); $s++)
{
                echo '<option value="conn ', "$unselect[$s]", '">', "$unselect[$s]";
}
echo "</select>";

I trimmed the selected value of white spaces and left the connection
elements alone.  Note the value of $pltoload will be connection, connection,
connection or connection,connection,connection.  If anyone can tell why some
matches don't work when I can view the element in each array and they are
identical in the exception of the key value within their respective array.


Larry

PS. HTML-Kit kicks butt!



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to