I am working on a gallery for a multilingual website. Each language has it’s own directory en/filename.php and nl/filename.php but are using the same php file to display the gallery. The table gallery has the following two fields: description_en and description_nl. In order to echo the right description I have created a variable called lang ($lang=“en” and $lang=“nl”) in each directory. I am looking for a way to create some kind of dynamic variable, if you call it that way? Something like the following:
If you want to use a variable as part of your array key, you have two choices:
// with a single quoted string
$description = $row['description_'.$lang];
// with a double quoted string
$description = $row["description_$lang"];
With a single quoted string, you have to use a . to concatenate the variable with the string, whereas when using double quotes, you can include the variable within the string and PHP will replace it with the value.
Hi Karl. I hear what you say and understand. Normally this would be my approach as well. Only this was an already existing website when I started to work on the site, so I left it this way. But thank you anyway.