Jump to content

finding duplicate. very simple


coder9

Recommended Posts

Hi

 

i have 5 random numbers

 

every time i refresh the page it generate 5 random numbers.

 

how do i check them that there are no duplicate numbers between the five numbers.

 

let say 1, 4, 3, 4, 7

 

as you can see the 2nd and 4th are the same.

 

can you show me some code that will detect them in vice versa.

 

or is there a built in function in php that will do this.

 

 

Thank you.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/116378-finding-duplicate-very-simple/
Share on other sites

make sure it doesn't generate duplicate numbers in the first place is easier...

 

google these things  ;)

 

<?php
$numbers = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,
26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49);
$pkt = array();
shuffle($numbers);
for ($i=1;$i<7;$i++){
$pkt[] = $numbers[$i];
}
sort($pkt);
echo "Randomly Generated Lotto Numbers <br />";
for ($d=0;$d<6;$d++){
    echo "$pkt[$d] ";
}
?>

 

http://www.spikemeister.co.uk/?p=94

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.