The difference between echo(), print(), print_r(), var_dump() in php
Oct 19, 2016 am 10:19 AM
echo() function: Output one or more strings. In fact, it is not a function, so there is no need to use parentheses on it, just use echo. However, if you wish to pass more than one argument to echo(), using parentheses will generate a parsing error. The echo() function is slightly faster than print(). When echo outputs multiple strings, separate them with commas.
For example 1: (Write the value of the string variable $str into the input)
$str="hello world!";
echo $str;
?>
Run result: hello world!
Example 2: (echo outputs multiple strings)
echo 'a','b','c';
print() function: Output one or more strings. Like echo, it is not actually a function. Print has a return value, but echo does not. When its execution fails, it returns false, and if it succeeds, it returns true. The speed is slightly slower than echo. Only the values ??of simple type variables can be printed out, such as int and string.
For example 1: (Write the value of the string variable $str to the output)
$str="hello world!";
print $str;
?>
print_r() function: can print out the value of complex type variables. Print_r() can be used to print out the entire array content and structure, displaying keys and elements in a certain format. In fact, it is not only used for printing, but for printing easy-to-understand information about variables.
For example 1: (Print array $age)
$age=array(18,20,24);
print_r($age);
?>
Run result: Array ( [0] => 18 [1] => 20 [2] => 24 )
var_dump() function: determines the type and length of a variable, and outputs the value of the variable. If the variable has a value, the value of the variable is output, and the data type is returned. This function displays structural information about one or more expressions, including the expression's type and value. Arrays will expand values ??recursively, showing their structure through indentation.
Example 1:
$age=array(18,20,24);
var_dump($age);
?>
Run result: array(3) { [0]=> int(18) [1]=> int(20) [2]=> int(24) }

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)