Jump to content

Getting Keys For Array Value


Crew-Portal

Recommended Posts

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.