php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9633 sort() not working
Submitted: 2001-03-08 13:43 UTC Modified: 2001-03-09 11:29 UTC
From: sgarin at sgarin dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.0.4pl1 OS: Linux 2.2.18
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: sgarin at sgarin dot com
New email:
PHP Version: OS:

 

 [2001-03-08 13:43 UTC] sgarin at sgarin dot com
I have an array with random number of elements. I analyse each value (by random selection) and unset it after. In one case, If I unset the first element of my array with 2 elements, sort function does not slide value of the second element to the first element. (sorry for my english). 

Exemple :

<?PHP 
  $tb = array (5, 18, 11);
  echo "Values: [0]=$tb[0] [1]=$tb[1] [2]=$tb[2]<BR>";
  unset ($tb[0]);
  echo "After unset: [0]=$tb[0] [1]=$tb[1] [2]=$tb[2]<BR>";
  sort ($tb);
  echo "After sort: [0]=$tb[0] [1]=$tb[1] [2]=$tb[2]<BR>";
  unset ($tb[0]);
  echo "After unset: [0]=$tb[0] [1]=$tb[1]<BR>";
  sort ($tb);
  echo "After sort: [0]=$tb[0] [1]=$tb[1]";
?>

I resolved this trouble by calling implode and explode functions.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-09 11:29 UTC] andre@php.net
bogus,
try using var_dump() on $tb to figure out what happens,
sort() is fine indeed...
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 16:01:31 2025 UTC