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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
10 - 4 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 14:01:28 2024 UTC