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
https://forums.phpfreaks.com/topic/271425-getting-keys-for-array-value/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.