Los parámetros de URL y recibidos de una variable global llamada $_GETque de hecho es una matriz. Entonces, para saber si una URL contiene un parámetro, puede usar la isset()función.
if (isset($_GET['yourparametername'])) {
//The parameter you need is present
}
Posteriormente, puede crear una matriz separada de dicho parámetro que necesita adjuntar a una URL.
Por ejemplo:
if(isset($_GET['param1'])) {
\\The parameter you need is present
$attachList['param1'] = $_GET['param1'];
}
if(isset($_GET['param2'])) {
$attachList['param2'] = $_GET['param2];
}
Ahora, para saber si necesita o no un ?símbolo, solo cuente esta matriz
if(count($attachList)) {
$link .= "?";
// and so on
}
Actualizar:
Para saber si se establece algún parámetro, solo cuente $ _GET
if(count($_GET)) {
//some parameters are set
}