How to track the number of variables in an array?

Posted on 2011-04-28
Last Modified: 2012-05-11
If I have an array that is filled with stored $_GET variables how can I know the stored amount?

Would a simple count($_SESSION['cart']) work??
Question by:FairyBusiness
    LVL 82

    Accepted Solution

    if $_SESSION['cart'] IS an array, then yes,

    will tell you how many items are stored in that array.

    Author Closing Comment

    LVL 82

    Expert Comment

    FYI: Using a foreach you can then iterate over its contents:
    foreach( $_SESSION['cart'] as $i=>$value )
     echo $i . " " . $value . "<br />";

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now