php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17316 fails to ignore case
Submitted: 2002-05-20 15:01 UTC Modified: 2002-06-17 15:34 UTC
From: swoo at gvlabs dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.2.1 OS: any
Private report: No CVE-ID: None
 [2002-05-20 15:01 UTC] swoo at gvlabs dot 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-17 07:46 UTC] hholzgra@php.net
reproduced on linux using CLI
 [2002-06-17 15:34 UTC] rodif_bl@php.net
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>";



 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Dec 08 15:01:25 2019 UTC