
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
What is the difference between echo, print, and print_r in PHP?
The print and echo are both language constructs to display strings. The echo has a void return type, whereas print has a return value of 1 so it can be used in expressions. The print_r is used to display human-readable information about a variable.
Example
Let us now see an example that displays output using echo, print, and print_r:
<?php $arr = array( "John", "Jacob", "Tom", "Tim"); echo "Array...
"; foreach( $arr as $value ) { echo "Value = $value
"; } echo "
Displaying Array Values using print...
"; foreach( $arr as $value ) { print( "Value = $value
"); } echo "
Displaying Array Values using print_r...
"; print_r($arr); ?>
Output
This will produce the following output−
Array... Value = John Value = Jacob Value = Tom Value = Tim Displaying Array Values using print... Value = John Value = Jacob Value = Tom Value = Tim Displaying Array Values using print_r... Array ( [0] => John [1] => Jacob [2] => Tom [3] => Tim )
- Related Articles
- Difference between print() and println() in Java
- print() function in PHP
- What is the difference between $ and @ in R?
- How to echo print statements while executing an SQL script?
- What is the difference between NA and in R?
- What is the difference between na.omit and complete.cases in R?
- What is the difference between na.omit and na.rm in R?
- What is the difference between array_merge and array + array in PHP?
- echo() function in PHP
- Print the time an hour ago PHP?
- PHP program to print the number pattern
- What is the difference between order and rank function in R?
- What is the difference between class and typeof function in R?
- PHP print keys from an object?
- Print newline in PHP in single quotes\n

Advertisements