Fw: [PHP-DEV] New function: array_change_key_case() From: Edin Kadribasic (edink <email protected>)
Date: 09/27/01

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 <email protected> > For additional commands, e-mail: php-dev-help <email protected> > To contact the list administrators, e-mail: php-list-admin <email protected>

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
For additional commands, e-mail: php-dev-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>