vmicchia Posted February 8, 2011 Share Posted February 8, 2011 I have an array. When I print it it looks like this: Array ( [1] => Array ( [Cushion] => Cushion 1 [Fabric] => f-111111 [FabricPrice] => 0 [Fill] => Fiber [button] => none [ContWelt] => none [ContWeltFabric] => none [Zipper] => N [Quantity] => 2 [WeltSize] => [sKU] => c-111111 [Edge] => Knife [Cap] => N [straps] => N [Hinged] => N [Type] => Boxed Button [Price] => 54.25 [Total] => 108.5 ) [2] => Array ( [Cushion] => Cushion 1 [Fabric] => f-111111 [FabricPrice] => 0 [Fill] => Fiber [button] => none [ContWelt] => none [ContWeltFabric] => none [Zipper] => N [Quantity] => 4 [WeltSize] => [sKU] => c-111111 [Edge] => Knife [Cap] => N [straps] => N [Hinged] => N [Type] => Boxed Button [Price] => 54.25 [Total] => 217 ) ) Now when I use count() I get a result of 01 when I should get 02 when I use count( ,1) I get a result of 381. I am Using this wrong? the array is stored in $_SESSION['cushArray'] Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 8, 2011 Share Posted February 8, 2011 How are you using count()? Post the code, please. Quote Link to comment Share on other sites More sharing options...
vmicchia Posted February 8, 2011 Author Share Posted February 8, 2011 No problem. I have tried: $count = count($_SESSION['cushArray'], 1); echo $count; result = 381 also $count = count($_SESSION['cushArray']); echo $count; result = 21 $count = count($_SESSION['cushArray'], COUNT_RECURSIVE); echo $count; result = 38 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 8, 2011 Share Posted February 8, 2011 Something about that seems odd. Can you post the output of this please? The <pre> formatting will make it much easier to see what the structure actually is. echo '<pre>'; print_r($_SESSION['cushArray']); echo '</pre>'; Quote Link to comment Share on other sites More sharing options...
vmicchia Posted February 8, 2011 Author Share Posted February 8, 2011 seemed odd to me too. but here it is: Array ( [1] => Array ( [Cushion] => Cushion 1 [Fabric] => f-111111 [FabricPrice] => 0 [Fill] => Fiber [button] => none [ContWelt] => none [ContWeltFabric] => none [Zipper] => N [Quantity] => 2 [WeltSize] => [sKU] => c-111111 [Edge] => Knife [Cap] => N [straps] => N [Hinged] => N [Type] => Boxed Button [Price] => 54.25 [Total] => 108.5 ) [2] => Array ( [Cushion] => Cushion 1 [Fabric] => f-111111 [FabricPrice] => 0 [Fill] => Fiber [button] => none [ContWelt] => none [ContWeltFabric] => none [Zipper] => N [Quantity] => 4 [WeltSize] => [sKU] => c-111111 [Edge] => Knife [Cap] => N [straps] => N [Hinged] => N [Type] => Boxed Button [Price] => 54.25 [Total] => 217 ) ) Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 8, 2011 Share Posted February 8, 2011 When I construct that array locally, and echo the count, it shows 2. I can't reproduce the issue, so troubleshooting it ain't gonna be easy . . . Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted February 9, 2011 Share Posted February 9, 2011 He is right. There is nothing wrong with that array. Which leads me to believe that perhaps the session is being overwritten at some point. Can you please post the entire code. Everything on the entire page (minus sensitive data) so I can get a better look. Rule out the session getting overwritten, or some other logic error in the way your structuring it. Quote Link to comment Share on other sites More sharing options...
vmicchia Posted February 9, 2011 Author Share Posted February 9, 2011 <?php echo '<pre>'; print_r($_SESSION['cushArray']); echo '</pre>'; $count = count($_SESSION['cushArray'], 1); echo $count; $total = 0; if(isset($_SESSION['cushArray'])){ $total = $total + count($_SESSION['cushArray'][1]['Cushion']); //echo 'This is the count: '.$count; } if(isset($_SESSION['umbArray'])){ $total = $total + count($_SESSION['umbArray']['Umbrella']); } if(isset($_SESSION['sampleArray'])){ $total = $total + count($_SESSION['sampleArray']['SKU']); } if(isset($_SESSION['cordingArray'])){ $total = $total + count($_SESSION['cordingArray']['Cording']); } if(isset($_SESSION['fringeArray'])){ $total = $total + count($_SESSION['fringeArray']['Fringe']); } if(isset($_SESSION['fabricArray'])){ $total = $total + count($_SESSION['fabricArray']['Fabric']); } if(isset($_SESSION['pillowArray'])){ $total = $total + count($_SESSION['pillowArray']['Pillow']); } if(isset($_SESSION['otherArray'])){ $total = $total + count($_SESSION['otherArray']['Product']); } echo $total; if($total != 0){ echo '<div class="carticon"><img src="images/fullcart.png" /></div>'; echo '<br />'; echo '<div class="cartstatus">'.$total.' items in cart.</div>'; }else{ echo '<div class="carticon"><img src="images/emptycart.png" /></div>'; echo '<br />'; echo '<div class="cartstatus">Cart is empty.</div>'; } ?> I'm only concerned with the first if statement really because it's the only session with any variables at the moment but that is the code from the page. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted February 9, 2011 Share Posted February 9, 2011 Where is your session_start(), or do you have them set to auto-start? Quote Link to comment Share on other sites More sharing options...
vmicchia Posted February 9, 2011 Author Share Posted February 9, 2011 I had it set to auto but I added it in the code just to be safe since you brought it up and I'm still having the same problem. Quote Link to comment Share on other sites More sharing options...
vmicchia Posted February 9, 2011 Author Share Posted February 9, 2011 Well I thank you for your help I just found my issue and it was just something dumb. I left in some echo statements I had not ment to which made it look like a different number. Thank you for all your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.