Bug #18096: sorting using usort() does not work
| From: | andre dot lourenco at link dot pt | Date: | Mon, 01 Jul 2002 19:20:58 +0000 |
| Subject: | Bug #18096: sorting using usort() does not work | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-12695@lists.php.net to get a copy of this message | ||
From: andre.lourenco@link.pt
Operating system: OSF1 V4.0 1091
PHP version: 4.2.1
PHP Bug Type: Arrays related
Bug description: sorting using usort() does not work
This code works on a PHP Version 4.1.0 with
Linux dorado 2.2.16-22smp #1 SMP Tue Aug 22 16:39:21 EDT 2000 i686
unknown
SYSTEM
Apache/1.3.24 (Unix) PHP/4.2.1
BEGIN -- index.html --
<html lang="pt">
<head>
<title>118 TEL</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0"
marginwidth="0"
marginheight="0" background="imagens/fund
o.gif">
<select>
<?
if (!isset($pais) || $pais == '-')
echo "<option value=\"-\" selected>- escolha o país
-</option>\n";
define ("S_ACENTOS",
"ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ");
define ("S_NORMAIS", "AAAAAAACEEEEIIII NOOOOOOOUUUUY aaaaaaaceeeeiiii
nooooooouuuuy ");
function cmp($a, $b) {
if ($a[1] == $b[1]) {
$s1 = strtr($a[2], S_ACENTOS, S_NORMAIS);
$s2 = strtr($b[2], S_ACENTOS, S_NORMAIS);
} else {
$s1 = strtr($a[1], S_ACENTOS, S_NORMAIS);
$s2 = strtr($b[1], S_ACENTOS, S_NORMAIS);
}
return strcmp($s1, $s2);
}
//$j=0;
$data = file("servicos.csv");
foreach ($data as $i) {
$linha = explode(";", Chop($i));
$csv[] = $linha;
}
usort($csv, cmp);
$ant = "";
$ser = "";
foreach ($csv as $i) {
if ($i[1] != $ant) {
echo "<option value=\"$i[0]\"";
if (isset($pais) && $pais == $i[0]) {
echo " selected";
$ser = $i[1];
}
echo ">$i[1]</option>\n";
}
if ($ser == $i[1]) {
$servicos[] = array($i[0], $i[2]);
}
$ant = $i[1];
}
?>
</select>
</body>
</html>
END -- index.html --
BEGIN -- servicos.csv --
1;Reino Unido;Thomweb - Thomson
Directories;http://www.infospace.com/uk.thomw/
2;Reino Unido;Electronic Yellow Pages;http://www.eyp.co.uk/
3;Reino Unido;Ask Alex Directory;http://www.askalex.co.uk/
4;Bélgica;Infobel;http://www2.infobel.be/infobel/
5;Eslovénia;Telefonski Imenik Slovenije;http://tis.telekom.si/
6;Suiça;Swisscom;http://www.whitepages.ch/
7;Andorra;Guia Electronica - Pàginas Blancas;http://www.laguia.ad/
8;Andorra;Guia Electronica - Pàginas
Amarillas;http://www.laguia.ad/gyeselluxe.asp?lang=ENG
9;Suécia;Gula Sidorna;http://www.gulasidorna.se/main/frameset.asp
10;Áustria;Telekom Austria;http://www.etb.at/
END -- servicos.csv --
--
Edit bug report at http://bugs.php.net/?id=18096&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=18096&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=18096&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=18096&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=18096&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=18096&r=support
Expected behavior: http://bugs.php.net/fix.php?id=18096&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=18096&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=18096&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=18096&r=globals