Jump to content

Recommended Posts

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']

Link to comment
https://forums.phpfreaks.com/topic/227088-help-counting-an-array/
Share on other sites

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

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>';

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

        )

 

)

 

 

 

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.

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

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.