dadamssg Posted May 13, 2012 Share Posted May 13, 2012 Say i have two arrays with custom keys. What would be the easiest way to write a function that would determine if all the keys in arrayOne are in arrayTwo? The example below would return false because keys 3 and 4 are missing in arrayTwo. Any help would be much appreciate. thanks! <?php $arrayOne['1'] = "adg"; $arrayOne['2'] = "a4g"; $arrayOne['3'] = "346"; $arrayOne['4'] = "etwe"; $arrayTwo['1'] = "xcb"; $arrayTwo['2'] = "acbr"; $arrayTwo['6'] = "yiy"; $arrayTwo['7'] = "mmm"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/262483-array-keys-matching-function/ Share on other sites More sharing options...
Pikachu2000 Posted May 13, 2012 Share Posted May 13, 2012 If you're trying to make sure both arrays have identical keys, array_diff_keys is what you need. Quote Link to comment https://forums.phpfreaks.com/topic/262483-array-keys-matching-function/#findComment-1345172 Share on other sites More sharing options...
Barand Posted May 13, 2012 Share Posted May 13, 2012 or if (array_keys($arrayOne) == array_keys($arrayTwo) Quote Link to comment https://forums.phpfreaks.com/topic/262483-array-keys-matching-function/#findComment-1345174 Share on other sites More sharing options...
dadamssg Posted May 13, 2012 Author Share Posted May 13, 2012 perfect @barand. exactly what i needed. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/262483-array-keys-matching-function/#findComment-1345184 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.