tags:

views:

42

answers:

2

Hi, some "simple" problem:

I've this array;

$myArray = array(
'FOO',
'BAR,
);

i want :

$mayArray = array(
   'FOO' => array(),
   'BAR' => array(),
);

in the moment iam doing it with an foreach:

foreach ($myArray as $key => $val) {
    $newArray[$val] = array();
}

$myArray = $newArray;

is there an easyer way ? ;-)

+5  A: 

The way you have is pretty easy to understand. But you can also do this:

 $myArray = array_fill_keys($myArray, array());

Docs here: http://us2.php.net/manual/en/function.array-fill-keys.php

Scott Saunders
you was few seconds faster than me )
Nazariy
+4  A: 

You can use array_fill_keys, here is example:

$myArray = array_fill_keys($myArray, array());
Nazariy