Introduction
Output functions show information to the user. They help your program talk to people.
Output functions show information to the user. They help your program talk to people.
echo 'text'; print 'text'; print_r($variable);
echo and print show text or variables.
print_r is useful to display arrays or objects.
echo 'Hello, world!';
$name = 'Alice'; echo "Hello, $name!";
$arr = [1, 2, 3]; print_r($arr);
This program prints a greeting with a name and then prints an array of colors.
<?php // This program shows a greeting message $name = 'Bob'; echo "Hello, $name!\n"; // Show an array $colors = ['red', 'green', 'blue']; print_r($colors); ?>
Use echo for simple output; it is faster and common.
print returns 1, so it can be used in expressions but is slower.
print_r is great for debugging arrays and objects but not for user-friendly output.
Output functions let your program communicate with users.
Use echo or print to show text or variables.
Use print_r to display arrays or objects for debugging.
echo and print in PHP?echo and print are used to show text or variables on the screen.echo "Hello World";.$arr = [1, 2, 3];
print_r($arr);
print_r prints human-readable information about arrays, showing keys and values.echo "Hello World"
print "!";
$data = ["user" => ["name" => "Anna", "age" => 25]];
echo and print cannot display arrays properly; they show errors or 'Array'.print_r prints arrays in a human-readable way, showing keys and nested values clearly.print_r because it prints readable array structure -> Option BPass the test and this pattern moves unknown