Re: Alter an Array Key

From: Date: Sat, 14 Jul 2007 05:02:31 +0000
Subject: Re: Alter an Array Key
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-258844@lists.php.net to get a copy of this message
On Fri, July 13, 2007 3:36 pm, 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. Not directly, but: $post = array(); foreach($_POST as $k => $v){ $k = str_replace('_', ' ', $k); $post[$k] = $v; } You could dink with unset instead, but it's a Bad Idea to alter what is actually in $_POST, imho. And you also don't really want to add new elements to an array while you iterate through it, generally... Though I think maybe foreach does the right thing with that. Better to build a new array and put the stuff you want into that. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So?

« previous php.general (#258844) next »