Hello
I have 2 variables that I want to join together.
$a = hello
$b = world
a + b = c
$c= hello world
i need to have a space between the variables i am joining.
thank you so much
Joining 2 Variables
Moderator: General Moderators
Re: Joining 2 Variables
What have you tried?
Re: Joining 2 Variables
I used implode()
is there anyway that if $middle_name is null that $firstmiddle becomes = to $first_name and no comma is added?
i also please need help with joining 3 variables together and adding a comma after the first one
example
$fulladdress = $town,$state $zip
i want a comma to be placed between $town and $state and only a space between $state and $zip
thank you!!!!
Code: Select all
$firstmiddle = implode(',', array($first_name,$middle_name));
is there anyway that if $middle_name is null that $firstmiddle becomes = to $first_name and no comma is added?
i also please need help with joining 3 variables together and adding a comma after the first one
example
$fulladdress = $town,$state $zip
i want a comma to be placed between $town and $state and only a space between $state and $zip
thank you!!!!
Re: Joining 2 Variables
Simplest answer is to just use the concatenation operator: .
You can also evaluate variables inside double quoted strings, so
is equivalent to the examples above.
Code: Select all
$fullname = $first_name . " " . $last_name;
$address = $city . ", " . $state . " " . $zip;Code: Select all
$fullname = "{$first_name} {$last_name}";
$address = "{$city}, {$state} {$zip}";Re: Joining 2 Variables
thank you
i am trying to make $firstmiddle = $firstname,$middlename with a comma separating
however if there is no middle name i want $firstmiddle = $firstname without a comma
this is what I'm trying now it doesn't seem to be working
i really appreciate all your help thanks for your patience
i am trying to make $firstmiddle = $firstname,$middlename with a comma separating
however if there is no middle name i want $firstmiddle = $firstname without a comma
this is what I'm trying now it doesn't seem to be working
Code: Select all
if (empty($middle_name)) {
$firstmiddle = $first_name;
} elseif (isset($middle_name)) {
$firstmiddle = $firstname . ", " . $middlename;
}
Re: Joining 2 Variables
i fixed it thank you very much i had variables wrong
thanks for your help
thanks for your help