Can I do this? (of course syntax is uncomplete) example:

// this code is supposed to be fixed)
$fieldname1 = 'real_name' // of mysql table
$afields = array($fieldname1,...)
$value1 = "abc"
$avalues = array($value1,...)
$sql = "INSERT INTO `table` ($afields[1]) VALUES ($avalue[1])"

// now I can ask for values (on the screen)
// and the user types in $value1 "xyz"
// then call the function

dowrite($afields, $avalues, $sql)

function dowrite($sql, $afields, $avalues){
// I don't want to pass the real names/values
// I want to pass the reference to them,
// so when the string $sql is evaluated/executed
// program will take the values existing at that moment
// in this case "xyz"