[PHP] unique array problem
I am facing one project in my project . this is my code: a=array(0=10,1=10,2=20,3=30,4=30,5=40); b=array(); b=array_unique($a); print_r($b); o/p getting from above code is b[0]=10,b[2]=20,b[3]=30,b[5]=40; but i want the o/p be b[0]=10,b[1]=20,b[2]=30,b[3]=40; i searched php.net .i am not able to fine any solution.i am breaking my head for last 5 hours.i am waiting reply from any one - Jiyo cricket on Yahoo! India cricket Yahoo! Messenger Mobile Stay in touch with your buddies all the time.
Re: [PHP] unique array problem
At 03:21 AM 4/22/2006, suresh kumar wrote: I am facing one project in my project . this is my code: a=array(0=10,1=10,2=20,3=30,4=30,5=40); b=array(); b=array_unique($a); print_r($b); o/p getting from above code is b[0]=10,b[2]=20,b[3]=30,b[5]=40; but i want the o/p be b[0]=10,b[1]=20,b[2]=30,b[3]=40; i searched php.net .i am not able to fine any solution.i am breaking my head for last 5 hours.i am waiting reply from any one Suresh, After you use array_unique() to remove duplicate values, can't you simply use sort() to impose consecutive keys? http://php.net/sort : This function sorts an array. Elements will be arranged from lowest to highest when this function has completed. Note: This function assigns new keys for the elements in array. It will remove any existing keys you may have assigned, rather than just reordering the keys. Paul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Unique Array
Hi Can anyone help me? I need to produce a random and uniques array using numbersbetween 0 and 9. I tried to create a random array and them make it unique. for ($i = 0; $i100; $i++){ $a[$i] = rand(0,9); $test=$a[$i]; } $ra = array_unique($test); I keep getting an error saying $test is the incorrect type. Can someone please explain why this doesn't work. And does anyone know how to get a unique and random array, every time the page is refreshed. Thanks Deirdre _ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp -- 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]