array with quantity

Discussion in 'PHP' started by dracula51, Jun 5, 2010.

  1. #1
    Hi
    say there's an array like this

    $a = array('as', 'bs', 'ds', 'bs', 'ds', 'bs');

    so there r 1 'as' 3 'bs' & 2 'ds'

    i want to show array result like this:

    'as' => 1
    'bs' => 3
    'ds' => 2



    how can i do it

    plz help....need it urgently :(
    plz
     
    dracula51, Jun 5, 2010 IP
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    $a = array('as', 'bs', 'ds', 'bs', 'ds', 'bs');
    print_r(array_count_values($a));
    PHP:
     
    digitalpoint, Jun 5, 2010 IP
    danx10 likes this.
  3. qrpike

    qrpike Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    or

    foreach($array as $key => $value){
    echo $key.'=>'.$value;
    }
     
    qrpike, Jun 6, 2010 IP
  4. dracula51

    dracula51 Peon

    Messages:
    146
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    tnx guys :)
     
    dracula51, Jun 7, 2010 IP