This is a discussion on compare within the MySQL forums, part of the Database Server Software category; --> How can I stop a function in PHP? When comparing data I want to stop the function on a ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| Piet wrote: > How can I stop a function in PHP? > > When comparing data I want to stop the function on a hit. > > > > Function compare($data) { > > For ($n=1; $n<=10000; $n++) { > > For ($m=1; $m<=10000; $m++) { > > If $data[$n]==data[$m] { > > . > > Exit function, or exit for.. --- but how? > > } > > } > > } > > How can I avoid comparing 10000 * 10000 times? > > > > Thanks > > > > Piet > > Among other ways - return can return from a function; break can break a loop. Or you can use a flag variable to indicate you wish to exit the loop. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
| |||
| Piet wrote: > How can I stop a function in PHP? > > When comparing data I want to stop the function on a hit. > > > > Function compare($data) { > > For ($n=1; $n<=10000; $n++) { > > For ($m=1; $m<=10000; $m++) { > > If $data[$n]==data[$m] { > > . > > Exit function, or exit for.. --- but how? > > } > > } > > } > > How can I avoid comparing 10000 * 10000 times? > > > > Thanks > > > > Piet > > (Ignore previous message - though I was in a different group). Depends in what language you're using to program. Check newsgroup for the language you're using. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
| ||||
| Piet wrote: > How can I stop a function in PHP? > > When comparing data I want to stop the function on a hit. > > > > Function compare($data) { > > For ($n=1; $n<=10000; $n++) { > > For ($m=1; $m<=10000; $m++) { > > If $data[$n]==data[$m] { Seems like you could load the data into a MySQL table, and use: SELECT val, COUNT(val) FROM mytable GROUP BY val HAVING COUNT(val) > 1 This will be very quick if you put an index on val. (I know this isn't answering your question directly, but this is a MySQL newsgroup, so I'm trying to use MySQL in the solution! ;-) Regards, Bill K. |