- Wrap the variables with double quotation marks or single quotation marks.
$var = 123;
$str = "This is a string with number $var";
- Use the dot operator (.) to concatenate strings and variables.
$var = 123;
$str = "This is a string with number " . $var;
- Use the sprintf function.
$var = 123;
$str = sprintf("This is a string with number %d", $var);
- Utilize the implode function
$arr = array('Hello', 'World');
$str = implode(' ', $arr);
- Utilize the json_encode function
$arr = array('Hello', 'World');
$str = json_encode($arr);
- Use the serialize function.
$arr = array('Hello', 'World');
$str = serialize($arr);