PHP Concatenation
You can join together direct text, and whatever is in your variable. The full stop (period or dot, to some) is used for this. Suppose you want to print out the following “My variable contains the value of 10”. In PHP, you can do it like this:
<?php
$first_number = 10;
$direct_text = 'My variable contains the value of ';
print($direct_text . $first_number);
?>
So now we have two variables. The new variable holds our direct text. When we’re printing the contents of both variables, a full stop is used to separate the two. Try out the above script, and see what happens. Now delete the dot and then try the code again. Any errors?
You can also do this sort of thing:
<?php
$first_number = 10;
print ('My variable contains the value of ' . $first_number);
?>
Leave A Comment?
You must be logged in to post a comment.