sort by alphabet and split into 4 even columns

Discussion in 'PHP' started by mmelen, Apr 29, 2008.

  1. #1
    mmelen, Apr 29, 2008 IP
  2. snatcher

    snatcher Active Member

    Messages:
    219
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    90
    Digital Goods:
    1
    #2
    put the list into an array, sort the array alphabetically (arsort i believe), then output 1/4 of the array elements using something like

    $numcolumns=4;
    $column=(int) (count($array)/$numcolumns);
    for($i=0;$i<$numcolumns;$i++) {
    for($x=0;$x<$column;$x++) {
    echo $array[$x];
    }}
     
    snatcher, Apr 30, 2008 IP
  3. mmelen

    mmelen Well-Known Member

    Messages:
    1,526
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    105
    #3
    how do I output the actual letters though?
    Like I want to output "A" before the A games start.
     
    mmelen, Apr 30, 2008 IP
  4. snatcher

    snatcher Active Member

    Messages:
    219
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    90
    Digital Goods:
    1
    #4
    $currentletter=substr($array[$x],0,1);
    if ($currentletter!==$previousletter) { echo $currentletter; $currentletter=$previousletter; }
     
    snatcher, Apr 30, 2008 IP