Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Location
    UK, London, Dartford
    Posts
    221
    Thanks
    3
    Thanked 14 Times in 14 Posts

    Grouping Arrays?

    I'm not sure if you can do this.

    I'm making a shoping cart, which uses Session, but for every quantity it takes the id number and adds it by one, so if i had product ID 1, but i wanted 10 quanty, it would show when i print it "1,1,1,1,1,1,1,1,1,1", is there anyway, when i use count($_SESSION['name']); it only counts one of the 1's? Same as if i had 10 2's or 10 3's?

    Let me no if you get what i mean hehe, thanks for the help.

  • #2
    Regular Coder Tyree's Avatar
    Join Date
    Sep 2003
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So, even if you have ten '2's, you don't want it to report "10" you want it to report "1"?

  • #3
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,839
    Thanks
    21
    Thanked 157 Times in 148 Posts
    Post your code.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #4
    Regular Coder
    Join Date
    Aug 2006
    Location
    UK, London, Dartford
    Posts
    221
    Thanks
    3
    Thanked 14 Times in 14 Posts
    Yes Tyree, that is correct
    Last edited by Lee Stevens; 11-30-2006 at 05:39 AM. Reason: Spaces dont show...

  • #5
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #6
    Regular Coder
    Join Date
    Aug 2006
    Location
    UK, London, Dartford
    Posts
    221
    Thanks
    3
    Thanked 14 Times in 14 Posts
    I have used them both i get a error.

    Al i need to do is count all the ones as one, and all twos as a two, etc etc.

  • #7
    Regular Coder Tyree's Avatar
    Join Date
    Sep 2003
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you did an array_count_values() on your array, couldn't you then just extract the keys that resulted to tell you the item IDs?

    PHP Code:
    <?php
    $array 
    = array(1,1,1,1,2,2,2,3,3,3,3);

    if (
    is_array($array)){

        
    $sepValues array_count_values($array);
        
        
    print_r($sepValues);
        print 
    "<br />";
        foreach (
    $sepValues AS $key=>$value)
              {
            print 
    "Item: ".$key." Quantity: ".$value."&nbsp;&nbsp;&nbsp;";
            }

    }
    ?>
    Output would be:
    Array ( [1] => 4 [2] => 3 [3] => 4 )
    Item: 1 Quantity: 4 Item: 2 Quantity: 3 Item: 3 Quantity: 4


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •