echo, print and printf
echo prints several values, print returns 1, and printf and sprintf format with %s %d %f. print_r and var_dump inspect values.
Example
echo "a", "b", "\n";
print "print\n";
printf("%s is %d years old and %.1f m tall\n", "Ada", 21, 1.68);
$s = sprintf("%05d|%-6s|", 42, "left");
echo $s, "\n";Result
ab print Ada is 21 years old and 1.7 m tall 00042|left |
Exercise
Format with placeholders.
("%d items", 3)Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.