[thelist] PHP - array manipulation

Peter Johansson peter at johansson.org
Fri May 10 16:10:00 CDT 2002


On Fri, 10 May 2002, Bill Haenel wrote:

> - I want to remove $array['month'], $array['day'], and $array['year'].
> - Then I want to turn them into
> "$array['year']-$array['month']-$array['day']".
> - Then I want to return that new value to the array as $array['date'].
>
> The array also contains many other key/value pairs.
> Any idea what the simplest method of doing this might be?

I'm not sure I understand exactly what you want, but perhaps something
like this would work?

<?php

$foo = array(
        'month'         => '05',
        'day'           => '10',
        'year'          => '2002',
        'body'          => 'Some text',
        'author'        => 'peter'
);

$foo['date'] = $foo['year'].'-'.$foo['month'].'-'.$foo['day'];
unset($foo['month']);
unset($foo['day']);
unset($foo['year']);

?>

./peter




More information about the thelist mailing list