Reputation: 8851
"CREATE TABLE IF NOT EXISTS $tables[users]";
Works but..
"CREATE TABLE IF NOT EXISTS $tables['users']";
Does not.
I do not want to do this
$usersTable = $tables['users'];
"CREATE TABLE IF NOT EXISTS $usersTable";
I heard that it was considered bad practice to reference a key from an associative array without some sort of quotes around it. Is this true or is my first way of doing it preferred?
Upvotes: 2
Views: 3161
Reputation: 1745
You could do the folling:
$query = sprintf("CREATE TABLE IF NOT EXISTS %s", $tables['users']);
// do some other stuff
Upvotes: 1
Reputation: 77074
You can do this with braces:
"CREATE TABLE IF NOT EXISTS {$tables['users']}";
Or through concatenation:
'CREATE TABLE IF NOT EXISTS ' . $tables['users'];
Upvotes: 8
Reputation: 8334
You can use curly brackets.
"CREATE TABLE IF NOT EXISTS {$tables['users']}";
Upvotes: 1