I'm trying to create a function that will display a piece of code that contains a variable outside of the function (IE Global variable) For instance, ideally this is what I'm trying to do: //Multiple different variables $first = "John"; $last = "Doe"; $age = "36"; $eyes = "Blue"; //Function to Display formatted variable function displayVariable($spec, $var){ if (isset($var)){ echo $spec.': '.$var.'<br />; } } displayVariable("First Name",$first); displayVariable("Last Name",$last); PHP: and get it to output: First Name: John Last Name: Doe Code (markup): without having to do tons of global variables. Am I on the right track?
That's the way to go - global variables are (usually) Not A Good Idea. You might want to read here: http://php.net/manual/en/language.functions.php to know a bit more how to get the maximum out of functions Happy coding!