0
Code:
$pessoa = "CARLOS";
$nome = explode ( " ", $pessoa, 2)[0];
$sobreNome = explode ( " ", $pessoa, 2 )[1] == null
? "VAZIO"
: "sobreNome: " . explode ( " ", $pessoa, 2 )[1] ;
print "Nome: " . $nome . "<br />";
print "sobreNome: " . $sobreNome;
Goal:
If explodes ( " ", $person, 2 )[1] it is not possible because the person only register 1 name, surname gets the term EMPTINESS
How to do?
Obs.: The way I made it makes the following mistake.
Notice: Undefined offset: 1 in D:\Trabalhos\host\htdocs\hotplateprensas.com.br\teste.php on line 9
Nome: CARLOS
VAZIO
In time:
If I do:
$pessoa = "CARLOS ALBERTO";
Then there’s no mistake.
I will accept your answer but I would like some guidance. What do you think of this approach? $surname = ! isset ( explodes ( " ", $person, 2 )[1] ) ? "EMPTY" : explodes ( " ", $person, 2 )[1] ;
– Carlos Rocha
@Carlosrocha Unnecessary. Why perform the same function 2x?
– Woss