Mar
25
2009
Our Love Language
The following is an actual email that I sent to my wife today. Â It’s talking about a coding function that I’ve been using that I find very handy. Â Please feel privileged that I am sharing such personal, lovey-dovey material.
Subject:
FFOTD – Favorite Function of the DayBody:
http://www.php.net/manual/en/function.array-diff-key.phparray array_diff_key ( array $array1 , array $array2 [, array $... ] )
Here’s the situation:
- I’m checking to see if the currently logged in user has certain roles to access a page
- I have 2 arrays, 1) the roles the user has, 2) the roles that they should have for access <= key’s set to the role_id
Instead of running a nested loop to see if the user has those roles, I just use array_diff_key to see what the deltas of the array keys are in both arrays. If there’s a delta, then NO ACCESS. If there’s no delta, then they are all good!
woot!
Anyone wanna go on a double-date with us?