|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20409 SORT_NUMERIC and non-numeric values
Submitted: 2002-11-13 09:20 UTC Modified: 2002-11-13 09:48 UTC
From: tadgher at yahoo dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.2.3 OS: FreeBSD
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: tadgher at yahoo dot com
New email:
PHP Version: OS:


 [2002-11-13 09:20 UTC] tadgher at yahoo dot com
This is the same problem discussed in bug #12848 (which is closed - could I have reopened it?).

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'

(built from FreeBSD ports collection)

// 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) {

// get it sorted by string
$array_sorted_str = $rand_array;
// get it sorted numerically
$array_sorted_num = $rand_array;

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).



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-11-13 09:48 UTC] tadgher at yahoo dot com
Sorry - I've just seen natsort()!
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Dec 09 02:05:54 2022 UTC