Re: Re: Ideas on modifying array keys
| From: | Gerard Samuel | Date: | Wed, 18 Feb 2004 17:28:01 +0000 |
| Subject: | Re: Re: Ideas on modifying array keys | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-178140@lists.php.net to get a copy of this message | ||
On Wednesday 18 February 2004 12:03 pm, Ben Ramsey wrote:
> You might be able to create some function that uses a combination of
> array_keys(), array_values(), and array_combine() to do what you want.
> Check the manual at http://www.php.net/array for more
> information on
> these functions.
>
True, but I was looking to see if I could avoid running a loop, of which I
would still have to loop over the result of array_keys() to modify its
content.
So for now, Im running ->
function modify_key($array)
{
$array = (array)$array;
foreach($array as $key => $value)
{
if (FALSE === ($pos = $strpos($key, '.')))
{
continue;
}
$new_key = substr($key, $pos + 1);
$array[ $new_key ] = $value;
unset( $array[ $key ] );
}
return $array;
}