Friday 13 September 2013

Changing a variable's value based on another variable in PHP

Changing a variable's value based on another variable in PHP

first let me say I am trying very hard to learn PHP, and the more I learn,
the more I want to learn and use the language. I'm primarily an HTML5/CSS3
coder, and am trying to make my sites more efficient by using PHP.
Here is my current dilemma. I am attempting to utilize variables to change
values as required. At the beginning of each page file I have declared the
page name, called my functions file and called head and header functions:
<?php
$page = 'contact';
include('functions.php');
head();
header();
?>
A slight variation of this is included in all page files. Things are good.
Now, in my functions.php I have a variable for the meta title value, i.e.
$title, and have declared it as a global.
How do I change the value of this variable based on the value of the $page
variable? Here is what I have added to the functions.php file, but I am
quite sure it is incorrect, as it is not working:
$title = array {
if ($page == 'contact') {
echo 'Contact Us';
}
}
I'm not just looking for the right code, but an explanation if possible.
Thanks in advance for your assistance.

No comments:

Post a Comment