So I know the code listed below has some functions that you won't be familiar with, but that shouldn't change the basics. I'm very new to programming and the concept of passing an array to a function and having it performed foreach "whatever" doesn't seem to make any sense to me.

Take a look at this example code:

I'm trying to figure out how I would loop through a list of classes which I can obtain by running GetMetadataInfo(). This code says "or set through a loop" which obviously should be very easy, but I'm racking my brain to figure out how to make this "loop" work. I have the code to put all the "$table_name" variables into an array, but then I cant seem to make a loop to create the "echo SQL" line for each class.
Code:
// gets resource information.  need this for the KeyField
$rets_resource_info = $rets->GetMetadataInfo();

$resource = "Property";
$class = "RES";
// or set through a loop

// pull field format information for this class
$rets_metadata = $rets->GetMetadata($resource, $class);

$table_name = "rets_".strtolower($resource)."_".strtolower($class);
// i.e. rets_property_res

$sql = create_table_sql_from_metadata($table_name, $rets_metadata, $rets_resource_info[$resource]['KeyField']);
echo "$sql";


function create_table_sql_from_metadata($table_name, $rets_metadata, $key_field, $field_prefix = "") {

        $sql_query = "CREATE TABLE {$table_name} (\n";

        foreach ($rets_metadata as $field) {

                $field['SystemName'] = "`{$field_prefix}{$field['SystemName']}`";

                $cleaned_comment = addslashes($field['LongName']);

                $sql_make = "{$field['SystemName']} ";

                if ($field['Interpretation'] == "LookupMulti") {
                        $sql_make .= "TEXT";
                }
                elseif ($field['Interpretation'] == "Lookup") {
                        $sql_make .= "VARCHAR(50)";
                }
                elseif ($field['DataType'] == "Int" || $field['DataType'] == "Small" || $field['DataType'] == "Tiny") {
                        $sql_make .= "INT({$field['MaximumLength']})";
                }
                elseif ($field['DataType'] == "Long") {
                        $sql_make .= "BIGINT({$field['MaximumLength']})";
                }
                elseif ($field['DataType'] == "DateTime") {
                        $sql_make .= "DATETIME default '0000-00-00 00:00:00' not null";
                }
                elseif ($field['DataType'] == "Character" && $field['MaximumLength'] <= 255) {
                        $sql_make .= "VARCHAR({$field['MaximumLength']})";
                }
                elseif ($field['DataType'] == "Character" && $field['MaximumLength'] > 255) {
                        $sql_make .= "TEXT";
                }
                elseif ($field['DataType'] == "Decimal") {
                        $pre_point = ($field['MaximumLength'] - $field['Precision']);
                        $post_point = !empty($field['Precision']) ? $field['Precision'] : 0;
                        $sql_make .= "DECIMAL({$field['MaximumLength']},{$post_point})";
                }
                elseif ($field['DataType'] == "Boolean") {
                        $sql_make .= "CHAR(1)";
                }
                elseif ($field['DataType'] == "Date") {
                        $sql_make .= "DATE default '0000-00-00' not null";
                }
                elseif ($field['DataType'] == "Time") {
                        $sql_make .= "TIME default '00:00:00' not null";
                }
                else {
                        $sql_make .= "VARCHAR(255)";
                }

                $sql_make .= " COMMENT '{$cleaned_comment}'";
                $sql_make .= ",\n";

                $sql_query .= $sql_make;
        }

        $sql_query .= "PRIMARY KEY(`{$field_prefix}{$key_field}`) )";

        return $sql_query;

}