-5
I want to have the title of the pages that are written in HTML replaced only when I insert a custom title. What function in PHP performs substitutions when the value is not NULL? How can I do this?
-5
I want to have the title of the pages that are written in HTML replaced only when I insert a custom title. What function in PHP performs substitutions when the value is not NULL? How can I do this?
4
Depends on what you call null.
The Stock 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 the ''
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 function !empty()
.
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 and also empty comparison table by clicking here.
properly upado. let’s hope to be that same the doubt :)
Browser other questions tagged php
You are not signed in. Login or sign up in order to post.
Not enough a
if( $valor === null )
?– Bacco
or even
if (!$valor)
– novic