PHP Array Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
munozca
Forum Newbie
Posts: 1
Joined: Fri Dec 03, 2010 10:00 am

PHP Array Help

Post 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!
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP Array Help

Post by Celauran »

Code: Select all

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