note 26311 added to function.sort

From: Date: Fri, 25 Oct 2002 21:54:53 +0000
Subject: note 26311 added to function.sort
Groups: php.notes 
Request: Send a blank email to php-notes+get-38570@lists.php.net to get a copy of this message
As I was prettying up the output I realized that removing that "-1" from the function creates an extra blank line in the array - but still is the only way I've found to get the final real line sorted. Here is the kludged version of my tabbed-ASCII table displayer that uses the function, which won't show the extra line if the value in the first column is empty. It also has an extra variable to set up top, $title. Other than that, it's to be pasted in place of the last half of the code in my post here just prior: $mem=file("$infile"); $line=explode("\t","$mem[0]"); $cnt=count($line); echo "<html><head><title>$title</title></head><body link=\"#ffff00\" alink=\#ff0000\" vlink=\"#00ffff\">"; echo "<table border=\"1\">"; echo "<tr><td colspan=\"$cnt\" bgcolor=\"#cc0000\"><font size=\"5\" color=\"#ffffff\">$title</font></td></tr><tr>"; for ($i=$firstcol;$i<$cnt;$i++) { echo "<td bgcolor=\"#000000\"><a href=\"$PHP_SELF?col=$i\">$line[$i]</a></td>"; } echo "</tr>"; $cnt=count($mem); for ($i=$firstcol;$i<$cnt;$i++) { $line=explode("\t","$mem[$i]"); $cnt2=count($line); for ($j=$firstcol;$j<$cnt2;$j++) { $mem2[$i][$j]=$line[$j]; } } if(!isset($col)) $col=$firstcol; $mem2=qsort_multiarray($mem2,$col); $x=1; for ($i=0;$i<$cnt;$i++) { for ($j=$firstcol;$j<$cnt2;$j++) { if ($mem2[$i][$firstcol]!="") { if ($j==$firstcol) { if ($x=="1") { echo "<tr>"; $x=0; } else { echo "<tr bgcolor=\"#dddddd\">"; $x=1; } } $show=$mem2[$i][$j]; if ($show=="") $show="&nbsp;"; echo "<td>$show</td>"; if ($j==($cnt2-1)) echo "</tr>"; } } } echo "</table></body></html>"; -- http://www.php.net/manual/en/function.sort.php http://master.php.net/manage/user-notes.php?action=edit+26311 http://master.php.net/manage/user-notes.php?action=delete+26311 http://master.php.net/manage/user-notes.php?action=reject+26311

« previous php.notes (#38570) next »