tags:

views:

65

answers:

3

Hello Everybody,

seems like i'm blind at the moment. I want to build an empty array(). but instead of getting "0" as array-key i want to have a specific string as the key... Just to make it clear:

$array = array();

gives me:

[0] => array {
}

but i want it like that:

["string"] => array {
}

...this really drives me crazy right now.

Thanks,Alex

+7  A: 
$array = array();
$array['string'] = "foo";  // this makes it so that $array['string'] = "foo"
$array[] = "bar";      // this makes it so that $array[0] = "bar"
$array[] = "barbar";   // this makes it so that $array[1] = "barbar"

print_r($array);

Output:

Array
(
    [string] => foo
    [0] => bar
    [1] => barbar
)

Hope this helps!

Axsuul
Even if this was not the Solution for my Problem, your Post helped me to find it. Thanks!!! P.S. i really was BLIND
mr.alex
+5  A: 

You mean like this?

$array = array('string' => array());

You might want to refresh your Array knowledge.

Gordon
+1  A: 

$array = array("string" => array())

?

DGM