SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast Sam32's Avatar
    Join Date
    Sep 2010
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Repeated items within an array

    Is there any function I can use to count repeated items within an array or should I use a variable?

    I have the following array:

    Code PHP:
    $arr = array(
        itemX,
        itemY,
        itemX,
        itemZ,
        itemY
    );

    I'm trying to print this:

    ItemX no. 1
    ItemY no. 1
    ItemX no. 2
    ItemZ
    ItemY no. 2

  2. #2
    Non-Member
    Join Date
    Jan 2011
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    array_count_values is what you need. Google it to get the page for it on the php manual.


Bookmarks

Posting Permissions

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