Hello i have a basic question.
I get 4 variables from a html formular: $var1, $var2, $var3, $var4
I want to put them in one string $string but sometimes not all variables are set but i want a seperator like "/".
Example:
$var1 = "I"
$var2 = "was"
$var3 = "not"
$var4 = "here"
Example one:
$string = $var1."/".$var2."/".$var3."/".$var4;
$string = I / was / not / here;
Example two:
$string = $var1."/".$var2."/".$var3."/".$var4;
$string = I / was / / here;
Can someone help me with the extreme basic question?
Thanks
2
Answers
You could put the data in an array, filter out nulls, and join to a string:
Try implode() on an array:
When a variable is not set, just do not put in the array.