tags:

views:

98

answers:

3

Why does this give me parse error? going crazy over here..

I have this file right:

function start_connection() {

 global $config['db_host'];

}

Parse error: parse error, expecting ','' or ';'' in functions.php on line 5

+2  A: 

You can't global an array within a variable. Only the variable.

Chacha102
+8  A: 

when declaring the global variable do not include the array key, so:

global $config;

this will provide access to all key => value pairs within $config array within the function start_connection().

nathan
+1  A: 

just do:

function start_connection() {
 global $config;
 echo $config['db_host'];
}

You can only use global variables, but not a specific value of a array.

Hippo
It's echo not echp. :)
KahWee Teng
ok, i have corrected this mistake :-P
Hippo