Home > Backend Development > PHP Problem > What is the difference between print_r and var_dump

What is the difference between print_r and var_dump

王林
Release: 2023-03-01 17:54:01
Original
3522 people have browsed it

The difference between print_r and var_dump is: the print_r function is used to print the content and structure of the array, and display the keys and elements according to a certain format; while the function var_dump is used to determine the type or length of a variable and output the value of the variable , and return the data type.

What is the difference between print_r and var_dump

Introduction to the difference between print_r and var_dump:

print_r() function

This function can Prints the value of a complex type variable. Use print_r() to print out the entire array content and structure, and display the keys and elements in a certain format. In fact, it's not just for printing, but for printing easy-to-understand information about variables.

For example: print array $age

<?php
    $age=array(18,20,24);
    print_r($age);
?>

//运行结果:Array ( [0] => 18 [1] => 20 [2] => 24 )
Copy after login

var_dump() function

This 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.

For example:

<?php
    $age=array(18,20,24);
    var_dump($age);
?>

//运行结果:array(3) { [0]=> int(18) [1]=> int(20) [2]=> int(24) }
Copy after login

If you want to know more related content, please pay attention to php Chinese website.

The above is the detailed content of What is the difference between print_r and var_dump. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template