Fw: [PHP-DEV] New function: array_change_key_case()

From: Date: Thu, 27 Sep 2001 08:18:32 +0000
Subject: Fw: [PHP-DEV] New function: array_change_key_case()
Groups: php.dev 
Request: Send a blank email to php-dev+get-66716@lists.php.net to get a copy of this message
Try #2 :) > Problem: > > I was faced with a problem of porting a large PHP application that was > originally written for Oracle to Postgres. The problem is that Oracle always > returns column names in uppercase, while Postgres does exactly the opposite. > So all the code that was handling rows returned from the database as > associative arrays did not work due to the case sensitivity of the array > keys. > > During the discussion on pear-dev it became apparent that was very difficult > to achieve the code portability in PEAR::DB for the same reason. Attempt to > write a PHP userspace function that will change the case of array keys was > benchmarked which produced very poor result. Passing each row returned from > database backed through that function resulted in performance loss of > 110-120%. > > Solution: > > There is a need for a function that will lowecase [or uppercase] all keys in > the associative array. After implementation and benchmarking the result > showed some ~15% performance loss which is much more acceptable than the > original ~120%. > > Function prototype: > > array_change_key_case(array input [, int case=CASE_LOWER|CASE_UPPER]) > /* Retuns an array with all string keys lowercased [or uppercased] */ > > Test case: > > $a=array("Ab"=>"test1", "AB"=>"test2", > "ac"=>3, 1=>"test3"); > $b=array_change_key_case($a, CASE_LOWER); > var_dump($a); > var_dump($b); > > Test result: > > array(4) { > ["Ab"]=> > string(5) "test1" > ["AB"]=> > string(5) "test2" > ["ac"]=> > int(3) > [1]=> > string(5) "test3" > } > > array(3) { > ["ab"]=> > string(5) "test2" > ["ac"]=> > int(3) > [1]=> > string(5) "test3" > } > > If there are no objections I would ask someone with CVS account to apply the > attached patch. > > Edin > ---------------------------------------------------------------------------- ---- > -- > PHP Development Mailing List <http://www.php.net/> > To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net > For additional commands, e-mail: php-dev-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

Attachment: [application/x-gzip] array.patch.gz
« previous php.dev (#66716) next »