Array Imploding erasing duplicates...?[SOLVED]
Posted: Wed Sep 05, 2007 8:31 am
Here is my short code for generating a random coupon number.
This gives me a 6 digit coupon. The problem, is that when I echo "$y[$x]";, in the middle of the code, I get the correct 6 digits. However, they are seperate, and to input them into sql later, I want to combine them into 1 string. So I found Array Implode. When I use it though, it does implode my array into 1 string, but any duplicate numbers/letters are lost. If my original echo "$y[$x]"; showed C59Q5B, then my echo after the implode reveals the new string as C59QB... the 5 between the Q and B has disappeared. This happens to any letter or number that occurs more than once. I looked at php.net/manual and could not find why this happens. NOTE-The comma's in the implode are not needed, just using them for visual easy for now.
Is Implode working as it is suppose to? Is there a way to use implode and not have it do what it is here? Or is there a better way to go about doing this. I'm just generating 6 random numbers, converting those to numbers or letters (excluding 0 and O), and then merging them into 1 string so I can input it into SQL. Thank you for any and all help.
-Mike-
Code: Select all
$convert_array = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z","1","2","3","4","5","6","7","8","9");
for ($i=0;$i<=1;$i++) {
for ($j=0;$j<=5;$j++) {
$before_array[] = rand (0, 33);
}
foreach ( $before_array as $x ) {
$y[$x] = $convert_array[$x];
echo "$y[$x]";
}
$coupon = implode(",",$y);
echo"<br /><b>$coupon</b><br /><br />";Is Implode working as it is suppose to? Is there a way to use implode and not have it do what it is here? Or is there a better way to go about doing this. I'm just generating 6 random numbers, converting those to numbers or letters (excluding 0 and O), and then merging them into 1 string so I can input it into SQL. Thank you for any and all help.
-Mike-