I have an array $used_logins with set of logins (can be large), and I need to generate an array of three unique logins like $login+rand(1, 1000); which wouldn’t be in $used_logins array.
How can I do this fastly?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you can’t do it in a database or such: Use the keys of
$used_loginsto store the data. And then check whether an element with the key exists.Depending on the sie of the array this can be faster thant the naive way using array search each time. (One creates a copy of the array, but array_search slower than a key access)