Show array

Discussion in 'PHP' started by jonathandey, Oct 5, 2010.

  1. #1
    How would I show this array

    Array ( [hGWMr8] => 7 [pQhe5H] => 1 )
    Code (markup):
    Like this

    hGWMr8 = 7
    pQhe5H = 1

    Thanks in advanced.
     
    jonathandey, Oct 5, 2010 IP
  2. learnerabn

    learnerabn Peon

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    i cant get ur question tell us in detail...
     
    learnerabn, Oct 5, 2010 IP
  3. jonathandey

    jonathandey Active Member

    Messages:
    112
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    If I use the following
    $select = mysql_fetch_object(mysql_query("SELECT * FROM websites WHERE id = '2'"));
    $who = explode(", ", $select->readby);
    $count = count($who);
    	 echo print_r(array_count_values($who));
    
    PHP:
    I get

    Array ( [hGWMr8] => 7 [pQhe5H] => 1 ) 
    Code (markup):
    How do I change that to this

    hGWMr8 = 7
    pQhe5H = 1
     
    jonathandey, Oct 5, 2010 IP
  4. learnerabn

    learnerabn Peon

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I dont know whether i have understood correctly or not.
    This example may help you..

    $fruits = array("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
    krsort($fruits);
    foreach ($fruits as $key => $val) {
    echo "$key = $val\n";
    }

    I got it from php.net
     
    learnerabn, Oct 5, 2010 IP
  5. learnerabn

    learnerabn Peon

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    For ur case u can surely use the example. instead of $fruits you can give ur $who array and get the ouptut.

    Still i dont know why u want to get this for an array, which is got by explode function...
    by default the explode funtion will return the index as 0,1,2,...

    or did set any key for the array previously?
     
    learnerabn, Oct 5, 2010 IP
  6. jonathandey

    jonathandey Active Member

    Messages:
    112
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #6
    Worked a treat thanks I did this

    
    <?
    $select = mysql_fetch_object(mysql_query("SELECT * FROM websites WHERE id = '2'"));
    $who = explode(", ", $select->readby);
    	 $thearray = array_count_values($who);
    krsort($thearray);
    foreach ($thearray as $key => $val) {
    echo "$key = $val\n";
    }
    
    ?>
    
    PHP:
     
    jonathandey, Oct 5, 2010 IP
  7. learnerabn

    learnerabn Peon

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Sorry i didnt noticed that you have used array_count_values in ur program so only i arised that qusetion...
    Any how u got that... so happy...
     
    learnerabn, Oct 5, 2010 IP