How can variables and constants be effectively integrated into strings for output in PHP scripts?
To integrate variables and constants into strings for output in PHP scripts, you can use concatenation or interpolation. Concatenation involves using the dot (.) operator to combine strings and variables/constants. Interpolation allows you to directly embed variables/constants within double-quoted strings. Example:
$name = "Alice";
$age = 30;
define("COUNTRY", "USA");
// Using concatenation
echo "Hello, " . $name . ". You are " . $age . " years old.";
// Using interpolation
echo "Hello, $name. You are $age years old. You are from " . COUNTRY . ".";