PHP

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);

?>

This time, the direct text is not inside a variable, but just included in the
Print statement. Again a full stop is used to separate the direct text from
the variable name. What you’ve just done is called concatenation. Try the new
script and see what happens.

|

Kaynak : https://www.homeandlearn.co.uk/php/php2p5.html ‘sitesinden alıntı

Yorum Yap