I've almost solved my array problem, but am just wondering if there is a better way to do this?
I have an array of ids stored in a $_SESSION var (from a previous page load), and when the page loads again, it gets a new array of ids from mysql. I want to compare the arrays (in the fastest way possible) to see if they are different, and if so, go do myfunc(). I'm not worried if the order has changed, just if there is a new id or one missing.
My code first does a simple sizeof comparison, and if there is a difference, no need to do any more testing, go straight to myfunc().
Bu if the sizes are the same, the id might still have changed, so my code then checks them like this:
I'm guessing the fix is to do a sort() of each array before the loop, but I'm wondering if there is a faster way overall to do it?
I tried figuring a way with isset after doing an array_flip, but array_flip didn't seem to swap keys and values in my arrays.
I would have used in_array, but I've read so many times that it's slow.
Thanks for your help.
Thanks Dormilich - I'll check them out.
|All times are GMT +1. The time now is 04:05 AM.|
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.