I have a set of PHP variables (that start with $cta
). I use a PHP 'If' test, to change the values of these variables depending on the values of other variables.
I use these variables in several locations in my PHP file (and wrap the variables in different HTML code depending on the location), so I want to store the 'If' testing code in a function.
That way, my code will be more efficient, as the 'If' test will be in one place.
Here is my function:
function calltoaction {
if ($cta_settings == 'cta_main') {
$cta_prompt = 'We are ready for your call';
$cta_button = 'Contact Us';
}
($cta_settings == 'cta_secondary') {
$cta_prompt = 'Call us for fast professional service';
$cta_button = 'Call Us';
}
}
Now that I have the function, how do I access the $cta variables inside of it?
E.g. The following doesn't work:
<?php
calltoaction();
print '<p>' . $cta_prompt . '</p>;
print '<span>' . $cta_button . '</span>;
?>
(The examples presented above are a cut down version, my full code is a bit more complex).