Jump to content

Script fails if value inside an array doesnt exist


UrbanDweller
 Share

Recommended Posts

Hey,

I have this code below which seems to completely fail sending my laptop cpu fan on a frenzy. All I am wanting to do is find whether the id in the url is located inside the array below else state its not in an error saying its not a valid id (for people who change the url shown below). At the moment it doesnt like the else statement if the isset clause it not true. (I have also tried, array_key_exists)

 

All I can think is that it get stuck looking for an id that doesnt exist inside the array but keeps searching though I dont know much about arrays etc. Besides this when a id is inside the array the script works like I want it to.

Any ideas would be much appreciated as this is hold me back at the moment :(

 

//url: http://localhost/website/shop.php?id=10197

// Array is built from table prior to this as it will grow in size
$_SESSION['storesProducts'] = Array ( [10197] => 0 [10198] => 0 [10199] => 1 [10200] => 1 [10201] => 1 [10202] => 1 [10205] => 0 [10206] => 1 [10207] => 1 )

if(isset($_SESSION['storesProducts'][$id])){
$storesProducts = $_SESSION['storesProducts'][$id];
if($storesProducts == 0){
	$list = $this->displayCategories($id);
}else{
	$createProducts = new constructProducts();
	$products = $createProducts->pagination($id);
}
}else{
$list = "ITS NOT HERE";
}
$output = new outputShop();
$output->display($list, $products);

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

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.

 Share

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