I have a two-dimensional array $array_userinfo with approx. 21,000 elements. Each element has ‘login’ in first position and ’email’ in the second position. What I need to do is to loop through this array and find any matching ‘login’ from another $array_usermeetingfolder, which is a one dimensional array with approx. 700 elements.
Here are the two arrays populated:
foreach ($child->children() as $node_principalid) {
array_userinfo[$i][0] = (string) $node_principalid->login;
$array_userinfo[$i][1] = (string) $node_principalid->email;
i++;
}
foreach (.......) {
$endusersconame = (string) $usermeetingsfoldersco->children()->name;
$array_usermeetingfolder[$j] = $endusersconame;//
$j++;
}
What is the best/efficient way way to do this? I have a loop like this:
for ($k=0;$k < count($array_userinfo);$k++) {
//tempecho($array_userinfo[$k][0]);//will yield login, such as, 'joeblow'
}
Thanks.
if it is possible you should use the login as an array key, then you can fast access the key and I think you don’t need to think about performance. Arrays in PHP are Hashmaps and if you know the key you can access it fast if you have to check the whole array it takes a lot longer. If you can not change it, you should think about creating a data structure from the array to habe this performance increase. Don’t know wether it’s worth, measure it 🙂
like: