Welcome
    

PHP Print

 

Similar to the echo statement, the print statement in PHP is used to output strings or variables directly to the web browser or client's screen. While print and echo are quite similar in functionality, there are some subtle differences in their behavior and usage.

 

 

Usage

 

 

The print statement is used to output strings or variables. It can be followed by one or more expressions or strings enclosed in quotes.

 

 

print "Hello, world!";
 

 

 

Return Value

 

 

Unlike echo, print always returns a value of 1, which can be useful in certain expressions or assignments.

 

 

$result = print "Hello, world!";
echo $result;
// Outputs: 1

 

 

Multiple Parameters

 

 

print does not support multiple parameters like echo. However, it can print the result of an expression directly.

 

 

$name = "John";
$age = 30;
print "Name: $name, Age: $age";

 

 


HTML Integration

 

 

As with echo, print can output HTML content and is commonly used to generate HTML tags, attributes, and dynamic content within PHP scripts.

 

 

$color = "blue";
print "<div style='color: $color;'>This text is blue.</div>";