Jump to content

Checking a sesion value with an array


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
https://forums.phpfreaks.com/topic/276647-checking-a-sesion-value-with-an-array/
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?

 

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

 

<?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.

<?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:

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.