echo, print, print_r, and var_dump are all statements or functions used to output or print values in PHP.
echo: echo is a language construct used to output one or more strings or variables. It can accept multiple parameters, each of which can be a string, number, variable, etc.
echo "Hello"; // 输出字符串"Hello"
echo "My name is " . $name; // 输出变量$name的值
echo $variable1, $variable2; // 输出两个变量的值
print: print is also a language construct used to output the value of a string or variable. Its syntax is similar to echo and can also accept multiple parameters.
print "Hello"; // 输出字符串"Hello"
print "My name is " . $name; // 输出变量$name的值
print $variable1, $variable2; // 输出两个变量的值
print_r: print_r is a function used to print the value of a PHP variable in a readable manner. It displays variables and their properties in a tree structure, often used for debugging and testing.
$person = array("name" => "John", "age" => 25);
print_r($person); // 打印数组$person的内容
var_dump: var_dump is a function that prints details of variables, including type and value. It will output the value of the variable and its size, type and other information.
$var = array("apple", "banana", "orange");
var_dump($var); // 打印数组$var的详细信息
These statements and functions are common output or printing methods in PHP, and you can choose a suitable statement or function to output or print values according to different needs.