From:             [EMAIL PROTECTED]
Operating system: FreeBSD
PHP version:      4.2.3
PHP Bug Type:     Arrays related
Bug description:  SORT_NUMERIC and non-numeric values

This is the same problem discussed in bug #12848 (which is closed - could I
have reopened it?).

Environment:
FreeBSD 4.7-PRERELEASE #1: Mon Sep 2 12:14:18 IST 2002  

Configure Command:
 './configure' '--with-apxs=/usr/local/sbin/apxs'
'--with-config-file-path=/usr/local/etc' '--enable-versioning'
'--with-regex=system' '--without-gd' '--without-mysql'
'--with-mhash=/usr/local' '--with-pgsql=/usr/local'
'--with-ldap=/usr/local' '--enable-xslt' '--with-xslt-sablot=/usr/local'
'--enable-trans-sid' '--with-expat-dir=/usr/local'
'--with-iconv=/usr/local' '--prefix=/usr/local'
'i386-portbld-freebsd4.7'

(built from FreeBSD ports collection)

Testcase:
<?php
// create an array
$array = array();
for ($i = 1; $i < 25; $i++) {
  array_push($array,"Dublin $i");
}
// randomise it
$rand_array = array();
srand ((float) microtime() * 10000000);
foreach (array_rand($array,sizeof($array)) as $index) {
  array_push($rand_array,$array[$index]);
}

// get it sorted by string
$array_sorted_str = $rand_array;
sort($array_sorted_str,SORT_STRING);
// get it sorted numerically
$array_sorted_num = $rand_array;
sort($array_sorted_num,SORT_NUMERIC);

echo "Original array";
echo "<ul>";
foreach ($array as $v) {
  echo "<li>$v</li>";
}
echo "</ul>";

echo "Randomised array";
echo "<ul>";
foreach ($rand_array as $v) {
  echo "<li>$v</li>";
}
echo "</ul>";

echo "array sorted by string";
echo "<ul>";
foreach ($array_sorted_str as $v) {
  echo "<li>$v</li>";
}
echo "</ul>";

echo "array sorted numerically";
echo "<ul>";
foreach ($array_sorted_num as $v) {
  echo "<li>$v</li>";
}
echo "</ul>";
?>
I would expect the numeric sort to give me Dublin 1, Dublin 2...Dublin
11,Dublin 12...Dublin 20 etc. 

While it does change the array, it appears to do so in a random fashion(at
least I cannot understand it).

Tadgh
-- 
Edit bug report at http://bugs.php.net/?id=20409&edit=1
-- 
Try a CVS snapshot:         http://bugs.php.net/fix.php?id=20409&r=trysnapshot
Fixed in CVS:               http://bugs.php.net/fix.php?id=20409&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=20409&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=20409&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=20409&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=20409&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=20409&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=20409&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=20409&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=20409&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=20409&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=20409&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=20409&r=isapi

Reply via email to