I want to make the title of the pages that are written in HTML be overwritten only when I insert a custom title. What function in PHP does overrides when the value is not NULL? How can I do this?
I want to make the title of the pages that are written in HTML be overwritten only when I insert a custom title. What function in PHP does overrides when the value is not NULL? How can I do this?
Depends on what it calls null.
Bacco's comment is correct, you simply use the comparison:
if($valor !== null){
// Substitui porque não está nulo
}else{
// Está nulo
}
However there is a difference between what is nulo
and what is vazio
, you can use ''
to identify the void.
if($valor !== ''){
// Substitui porque não está vazio
}else{
// Está vazio
}
In all cases, to identify if the value is not empty and also not null, you can use the non-restrictive comparators !=
instead of !==
(that is, you can use != null
or != ""
) or you can choose to use the !empty()
function.
if(!empty($valor)){
// Substitui porque não está nulo, não está vazio e não está indefinido
}else{
// Está "nulo"
}
You can see the null comparison table as well as the empty table by clicking here.