In this PHP tutorial, you shall learn how to concatenate a given string and number using String Concatenation Operator, with example programs.

PHP – Concatenate string and number

To concatenate string and number in PHP, convert the number to string using strval() function and then use string concatenation operator to concatenate both the values.


The syntax to concatenate the string str and number n is

$str . strval($n)

The function returns a string value.



1. Concatenate string and number

In this example, we take a string in str and a number in n. We concatenate these two values into a string.

PHP Program

  $str = 'apple';
  $n = 542;
  $output = $str . strval($n);
  echo $output;



In this PHP Tutorial, we learned how to concatenate string and number, using strval() function and string concatenation.