while ( $a = key($to_add) ) { while ($b = key($to_del)) { if ($a == $b){ ... } next($to_del); }; next($to_add); };