Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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 "\nDisplaying Array Values using print...
"; foreach( $arr as $value ) { print( "Value = $value
"); } echo "\nDisplaying 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 )
Advertisements
