Simple function - dynamic variable

Hi all

I have a simple php function which does other things amongst pulling some variables from the database.

In the function, they enter
getServerInfo($server, $centre, $host)

in the function, I have a long winded IF script to get the different variables

if($server == “1”){
$servername = $database[‘server1_name’];
} elseif($server == “2”)


Can I set it up so that it just automatically looks at the right server number depending on what they enter.

$servername = $database[‘server$server_name’];
$serverlocation = $database[‘server$server_location’];

Would make life a lot easier?


You’re looking for a dictionary, though an array can be used as well. Define the indexes and add the value. Then search if the index is in the array and poof there it is.

Your database table is laid out like a spreadsheet, with name/numbered columns, making every operation on the data more difficult and complicated. Research ‘database normalization’ to fix the design, then you can simply query to get the data that you want.

Sponsor our Newsletter | Privacy Policy | Terms of Service