echoing webpage title from the defined list

55 views Asked by At

I got a way to display custom page titles using include fuction.

Header:

<title><?php echo $pageTitle ?></title>

Include:

<?php
$pageTitle = "Pets:";
include '../header.php';
?>

So as to handle titles easier I'd like the name to come from the predefined list:

<?php
define('ANIMAL', 'Dog');
?>

How do I add 'ANIMAL' to the $pageTitle = "Pets:"?

1

There are 1 answers

0
The Onin On BEST ANSWER

To answer your question:

<?php
$pageTitle = "Pets:";
define("ANIMAL", "Dog");
$pageTitle .= ANIMAL;
echo $pageTitle; // yields "Pets:Dog";
?>

But to be fair, I would do it with arrays, not with constants in this case.

Something like this:

<?php
$pageTitle = "Pets:";
$animals = array('Dog', 'Cat', 'Bird', 'Super Cow');
echo $pageTitle . $animals[0]; // yields "Pets:Dog";
?>