Jump to content

Script fails if value inside an array doesnt exist


Recommended Posts


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 )

$storesProducts = $_SESSION['storesProducts'][$id];
if($storesProducts == 0){
	$list = $this->displayCategories($id);
	$createProducts = new constructProducts();
	$products = $createProducts->pagination($id);
$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. 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.

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.