Page 1 of 1

PHP Array Help

Posted: Fri Dec 03, 2010 10:22 am
by munozca
I need assistance in creating a new array from the following array:

Array (
[Diesel] => Diesel
[691.400000572205] => 691.400000572205
[Off-Road Diesel] => Off-Road Diesel
[1104.20000505447] => 1104.20000505447 )

I need to new array to look like this:
Array (
[Diesel] => 691.400000572205
[Off-Road Diesel] => 1104.20000505447 )

What's the best way to go about this?

Thanks!

Re: PHP Array Help

Posted: Fri Dec 03, 2010 11:21 am
by Celauran

Code: Select all

for ($i = 0; $i < count($array); $i += 2)
{
    $new_array[$array[$i]] = $array[$i + 1];
}
?