Re: Alter an Array Key

From: Date: Fri, 13 Jul 2007 20:52:35 +0000
Subject: Re: Alter an Array Key
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-258816@lists.php.net to get a copy of this message
On Fri, 2007-07-13 at 15:36 -0500, OD wrote: > Hello, > Is there any easy way to alter a key's name? > > I would like to remove some underscores in the $_POST array keys. <?php foreach( $_POST as $key => $value ) { if( strpos( $key, '_' ) !== false ) { $_POST[str_replace( '_', '', $key )] = $value; unset( $_POST[$key] ); } } ?> I would suggest NOT removing the original key though and just have both. To do so just comment out/remove the line that has unset(). Cheers, Rob. -- ........................................................... SwarmBuy.com - http://www.swarmbuy.com Leveraging the buying power of the masses! ...........................................................

« previous php.general (#258816) next »