SyntaxStudy
Sign Up
PHP Beginner 1 min read

PHP Variables & Echo

PHP Variables & Echo

Variables

Variables start with $. PHP is loosely typed — no need to declare the type.

echo vs print

Both output text. echo is slightly faster and can take multiple arguments. print always returns 1.

String Interpolation

Variables inside double-quoted strings are automatically replaced with their values.

Example
<?php
$name = "Alice";
$age  = 25;
$pi   = 3.14159;
$ok   = true;

echo $name;              // Alice
echo "Hello, $name!";   // Hello, Alice!
echo "Age: " . $age;    // concatenation

// print_r for arrays/objects
$arr = [1, 2, 3];
print_r($arr);
?>