ToonMariner Posted November 11, 2009 Share Posted November 11, 2009 Does any one know what/how imitations are applied to array_unique? I have an issue where no matter how big (as in over this limit) the array is array_unique always returns an array with 32768 elements.... It bothers me Quote Link to comment https://forums.phpfreaks.com/topic/181122-limitations-on-array_unique/ Share on other sites More sharing options...
sasa Posted November 11, 2009 Share Posted November 11, 2009 in my local machine (php5) this code <?php $test = range(1, 50000); $test = array_merge($test, $test); echo count($test)," \n"; $t = array_unique($test); echo count($t); ?> output 100000 50000 Quote Link to comment https://forums.phpfreaks.com/topic/181122-limitations-on-array_unique/#findComment-955670 Share on other sites More sharing options...
PFMaBiSmAd Posted November 11, 2009 Share Posted November 11, 2009 Yeah, it is more likely that the code you are using to generate the values has a limitation that is only producing that specific number of unique values. Quote Link to comment https://forums.phpfreaks.com/topic/181122-limitations-on-array_unique/#findComment-955718 Share on other sites More sharing options...
ToonMariner Posted November 11, 2009 Author Share Posted November 11, 2009 Not blowing my own but I dont think so... here is the code I'm trying to generate the 250000 unique strings... <?php $chars = "ABCDEFGHJKLMNPQRSTUVWXYZ"; $charend = (strlen ( $chars ) - 1); $date = date ( 'md' ); $month = $date[0].$date[1]; $year = $date[2].$date[3]; $datecode = $chars[$month] . $chars[$year[0]] . $chars[$year[1]]; $uniquecodes = array(); $no_codes = isset( $_GET['no_codes'] ) ? $_GET['no_codes'] : 250000; $codecount = 0; do { $codes = array(); for ( $j = $codecount ; $j < $no_codes ; $j++ ) { $trackcode = NULL; for ( $i = 0 ; $i < 7 ; $i++ ) { $x = rand( 0 , $charend ); $trackcode .= $chars[rand( 0 , $charend )]; } $codes[] = $trackcode . $datecode; } $unique = array_merge ( $codes , $uniquecodes ); $uniquecodes = array_unique ( $unique ); $codecount = count ( $uniquecodes ); if ( (time() - $start) > 60 ) { break; // just in to break out of infite loop in dev. } } while ( $codecount < ($no_codes) - 1 ); echo 'Unique Codes: ' . $codecount . PHP_EOL; ?> the date portion (last three characters) is used to keep keys separated by date - these are to be added to a database and i can check if any existing codes end in the same three characters (if they do then I'll manage that elsewhere). so essentially a 7 letter random string shouold yield 24^7 combos (I omitt I and O so as not to confuse with numbers) which works out at 4,500,000,000 so there should be plenty of room for manouvre. Could this be a memory limit issue or am I missing something much more fundamental? Cheers peeps. Quote Link to comment https://forums.phpfreaks.com/topic/181122-limitations-on-array_unique/#findComment-955877 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.