← PHP tutorial

PHP

Echo & String Concatenation

echo can print several things separated by commas, or you can join (concatenate) strings into one using the . operator.

Example: building a full name

<?php
  $first = "Chi";
  $last = "nedu";
  echo $first . $last;
?>
Chinedu

PHP uses . for string concatenation, worth noting explicitly, since many other languages (JavaScript, Python) reuse + for the same job, and reaching for + out of habit in PHP does something entirely different (numeric addition, which usually produces an unexpected result or a warning when applied to text).

Example
<?php
  $first = "Chi";
  $last = "nedu";
  echo $first . $last;
?>
Output
Chinedu
Ready to go further?

These free tutorials are a preview, our Backend Development cohort covers it in depth, with a real project and a cohort alongside you. Closes Nov 30

Enroll in Backend Development

Cookie preferences

Choose what you're comfortable with. You can change this any time from the footer.

Don't miss out

Ready to build something real?

Create a free account to enroll in a track, and get notified the moment a cohort opens.

Create free account