I know that it may be somewhat irrelevant to solving the problem at hand (and, in fact, I think your current method is probably the best method), but I was just wondering why you needed to change the names of your keys at all. Why is it not programmed so that the keys already have the names you want them to have?



Gerard Samuel wrote:

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;
}

-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to