Crew-Portal Posted December 1, 2012 Share Posted December 1, 2012 The website I am working on is a HRIS project for a popular fast food franchise chain. The login for one restaurant allows one user to modify all actions for all restaurants owned by the same franchisee. These are organized by multiple databases calling the same id's. Below is the code used for selecting all restaurants where the same franchise id is used as the restaurant login. $result = mysql_query("SELECT id, name FROM restaurants WHERE franchise = $_SESSION[sESS_RESTAURANT_FRANCHISE]"); $_SESSION['franchise_arr'] = array(); while($row = mysql_fetch_array($result)){ $_SESSION['franchise_arr'][$row['id']] = $row['name']; } So lets say for one login the SESSION array is populated like this: $_SESSION[sESS_RESTAURANT_FRANCHISE][1] = "Restaurant One"; $_SESSION[sESS_RESTAURANT_FRANCHISE][15] = "Restaurant Two"; $_SESSION[sESS_RESTAURANT_FRANCHISE][29] = "Restaurant Three"; I need a way to check to see if the KEY value is in an array as oppose to the value itself. For example I have: if (!in_array($rest, $_SESSION['franchise_arr'])){ $rest = $_SESSION['SESS_RESTAURANT_ID']; } However that checks for the values "Restaurant One", "Restaurant Two", "Restaurant Three". Where I would like it to look for "1", "15", or "29". I hope someone understands what I mean :\ I've been strugging with this for quite a while. Quote Link to comment https://forums.phpfreaks.com/topic/271425-getting-keys-for-array-value/ Share on other sites More sharing options...
Jessica Posted December 1, 2012 Share Posted December 1, 2012 isset($arr[$key]]) Quote Link to comment https://forums.phpfreaks.com/topic/271425-getting-keys-for-array-value/#findComment-1396572 Share on other sites More sharing options...
Crew-Portal Posted December 1, 2012 Author Share Posted December 1, 2012 isset($arr[$key]]) if (!isset($_SESSION['franchise_arr'][$rest])){ $rest = $_SESSION['SESS_RESTAURANT_ID']; } Works just great. Thank you. I can't believe I couldn't figure that one out. :\ Quote Link to comment https://forums.phpfreaks.com/topic/271425-getting-keys-for-array-value/#findComment-1396573 Share on other sites More sharing options...
akphidelt2007 Posted December 1, 2012 Share Posted December 1, 2012 array_key_exists Quote Link to comment https://forums.phpfreaks.com/topic/271425-getting-keys-for-array-value/#findComment-1396574 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.