Jump to content

Checking a sesion value with an array


eldan88
Go to solution Solved by eldan88,

Recommended Posts

Hey,

 

 I am trying to see if the current store_name session is equal to any of the session name I have assigned into the $store_array but I don't seem to be getting any luck. Below is my code. Any suggestions?

 

$store_array = array('store1', 'store2');

function chain_report(){ 
global $store_array;
if($_SESSION["store_name"] == $store_array) {

 

Link to comment
Share on other sites

Thanks for the post. I have tried the in_array function  below

 

$store_array = array("store1","store1");

function chain_report(){ 
global $store_array;
if(in_array($_SESSION["store_name"],$store_array)) {

 

I got the following error message..
Parse error: syntax error, unexpected T_IF, expecting ',' or ';'

 

What does that mean?

 

Link to comment
Share on other sites

That error doesn't reference those lines, it's most likely somewhere else in the function.

 

Post all of the code.

 

Hey Paul,

 

 I rewrote the function and this time its not showin that same error message, its just not showing anything.

 

Below is my functon I wrote

$store_array = array('demo', 'giorgios');

function chain_report2($store_session) {
	global $store_array;
	if(in_array($store_session,$store_array)){
		$output =  "Demo 1";
	} return $output;
	
}

Below is how I called the function

chain_report2($_SESSION["store_name"]);

Its not reurning the string "Demo 1" on neither sessions.

 

Please help..

Link to comment
Share on other sites

 

<?PHP

  $store_array = array('demo', 'giorgios');

  function chain_report2($store_session) {
    $output = '';
    
    global $store_array;
    if(in_array($store_session,$store_array)){
        $output .=  "Demo 1";
    }
    
    return $output;    
  }

  echo chain_report2($_SESSION['store_name']);
 
?>

 

You actually have to echo out the returned data for it to show.

Link to comment
Share on other sites

  • Solution
<?PHP

  $store_array = array('demo', 'giorgios');

  function chain_report2($store_session) {
    $output = '';
    
    global $store_array;
    if(in_array($store_session,$store_array)){
        $output .=  "Demo 1";
    }
    
    return $output;    
  }

  echo chain_report2($_SESSION['store_name']);
 
?>

You actually have to echo out the returned data for it to show.

 

Wow you are right!!!!! Thank you so much for your help! :happy-04: :happy-04: :happy-04:

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.