Set a flexible php variable

If you want php set a default variable value, but only if you yourself (in a particular case) set (before) another value of that variable, you can use a code like this:

$your_variable = $your_variable ?? $a_default_value;

That means: if you doesn’t define another value (with a code like $your_variable = "some_particular_value" ), the value of $your_variable will be $a_default_value.

Otherwise it will be "some_particular_value" .

How to avoid double slash

If your link points to a folder it should ends with a slash (/), but if you use a php variable to define it and you sometimes need to add some page at the end of your link, you could have a problem: the double slash (//).
I.g. you could have this variable php

$mypath="mypath1/mypath2/";

The final slash is recommended to avoid a redirect (that you would have with $mypath="mypath1/mypath2).
And you can call that variable in all your webpages pointing at that folder, in this way:

<a href=”<?php echo $mypath ?>”>some name</a>

But if you have to point to a specific page in that folder, you shouldn’t use this code:

<a href="<?php echo "$mypath/a-specific-page.php" ?>">some other name</a>

otherwise you will get, in the final html, a double slash. No way, course to write $mypatha-specific-page.php , because in this case your would call a not existing variable ($mypatha-specific-page.php ).

A good solution could then be this

<a href="<?php echo $mypath . 'a-specific-page.php' ?>">some other name</a>