Bug #17316 Updated: fails to ignore case
| From: | rodif_bl@php.net | Date: | Mon, 17 Jun 2002 19:34:58 +0000 |
| Subject: | Bug #17316 Updated: fails to ignore case | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-10927@lists.php.net to get a copy of this message | ||
ID: 17316
Updated by: rodif_bl@php.net
Reported By: swoo@gvlabs.com
-Status: Open
+Status: Bogus
Bug Type: Arrays related
Operating System: any
PHP Version: 4.2.1
New Comment:
natcasesort won't mess with the keys..
so you can have an array like this
$a['a'] = "apple";
$a['c'] = "car";
$a['z'] = "zebra";
$a['f'] = "Foobar";
$a['b'] = "Blank";
natcasesort($a);
and you still can say echo $a['a'] and get "apple".
now your array is indexed by integers so it still will keep the
interger index.
to fix this you should use foreach() both in the class and outside the
class (which you did)
not this:
for($i=0;$i<count($this->items);$i++){
echo $this->items[$i]."<br>";
}
but this:
foreach($this->items as $item)
echo $item . "<br>";
Previous Comments:
------------------------------------------------------------------------
[2002-06-17 07:46:22] hholzgra@php.net
reproduced on linux using CLI
------------------------------------------------------------------------
[2002-05-20 15:01:36] swoo@gvlabs.com
<?php
class test
{
var $items = array();
function stuff($listx){
for($i=0;$i<count($listx);$i++){
array_push($this->items,$listx[$i]);
}
}
function testsort1(){
echo "<hr>sort<hr>";
sort($this->items);
for($i=0;$i<count($this->items);$i++){
echo $this->items[$i]."<br>";
}
}
function testsort2(){
echo "<hr>natsort<hr>";
natsort($this->items);
for($i=0;$i<count($this->items);$i++){
echo $this->items[$i]."<br>";
}
}
function testsort3(){
echo "<hr>natcasesort<hr>";
natcasesort($this->items);
for($i=0;$i<count($this->items);$i++){
echo $this->items[$i]."<br>";
}
}
}
$t =
array("apple","car","zebra","Foobar","Blank");
$K = new test;
$K->stuff($t);
$K->testsort1();
$J = new test;
$J->stuff($t);
$J->testsort2();
$M = new test;
$M->stuff($t);
$M->testsort3();
echo "<hr>";
natcasesort($t);
foreach($t as $t2){
echo $t2."<br>";
}
?>
used the php binary for win32
natcasesort works outside of the class object as demonstated by the
last example.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=17316&edit=1