PDA

View Full Version : PHP Combining string variables;


Ooryl
29-03-2004, 19:03
If I have two string variables containing data eg. $firstname = Dave and $surname = Bloggs and I want to create a new variable by combining these two eg $name which would contain Dave Bloggs, how do I do this in PHP?

[M]uuhh
29-03-2004, 20:06
simple
<?

$firstname = "Dave";
$surname = "Bloggs";

$fullname = "$firstname $surname";
print "My name is $fullname.";

/////////

$firstname = "Dave";
$surname = "$firstname Bloggs";

print "My name is $surname.";


?>

Zozart
29-03-2004, 21:26
Or if you weren't bothered about keeping $firstname,
$firstname = "Dave"; $firstname .= " Bloggs";

Either method would work fine :eek:

Ooryl
30-03-2004, 16:06
Cheers for that. I suspect I will find both methods useful before I finish. :)

[M]uuhh
30-03-2004, 17:03
you may find Array() very useful for this type of scripting.